-2

I'm pretty new to OpenCL and wanted to check sizes of its different datatypes but attempting to print sizeof cl_int* gives segmentation fault. I can not find a logical reason for this.

#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <CL/opencl.h>
void main(){
cl_int a;
printf("size:%d\n",sizeof(size_t));
cl_int num = 10;
printf(sizeof(cl_int *));
exit(0);
//cl_int *data,*data_2,*data_3 = (cl_int *)malloc(num*sizeof(cl_int));
printf("Done!");
}
Martin James
  • 24,453
  • 3
  • 36
  • 60
manav.tix
  • 101
  • 2
  • 4
    `printf` expects a format string as first parameter. – tkausl Sep 02 '18 at 20:28
  • Does the code as shown compile warning free, even if you use strict warnings? – Yunnosch Sep 02 '18 at 20:35
  • Please explain what you intend to achieve with this line and additionally how you understand the syntax. `printf("%d",sizeof(cl_int *));`. – Yunnosch Sep 02 '18 at 20:36
  • Thanks now it is works fine. It would be great if you could tell me more about why this error occurred. – manav.tix Sep 02 '18 at 20:37
  • I was basically trying to find sizes of different OpenCL datatypes and had also put cl_int * just for curiosity but got stuck. I had used printf with sizeof() before too but had never encountered errors. Will keep this in mind for future. – manav.tix Sep 02 '18 at 20:40
  • 1
    Please don't edit code in questiions to as to invalidate comments/answers. It's very confusing for future visitors/users. – Martin James Sep 02 '18 at 20:47
  • Possible duplicate of [Definitive List of Common Reasons for Segmentation Faults](https://stackoverflow.com/questions/33047452/definitive-list-of-common-reasons-for-segmentation-faults) – JayC Sep 02 '18 at 21:18

1 Answers1

-1

You seems forgot about format of printf try something like this:

cl_int num = 10;                                                                                                                                                                                                                                                                          
printf("[%d]\n",sizeof(cl_int));                                                                                                                                                                                                                                                          
printf("[%d]\n",sizeof(num)); 
Boris Ivanov
  • 4,145
  • 1
  • 32
  • 40