printf makes error and don't show the result

南楼画角 提交于 2019-12-12 05:40:41

问题


i have problem with the printf in opencl this is the part of my code :

clGetEventProfilingInfo(timing_event, CL_PROFILING_COMMAND_START,
sizeof(time_start), &time_start, NULL);
clGetEventProfilingInfo(timing_event, CL_PROFILING_COMMAND_END,sizeof(time_end),
&time_end, NULL);
total_time = time_end - time_start;
printf("\nAverage Time In Nanoseconds  = %lu\n" , total_time );

and i have declared variables like this :

cl_event timing_event;
cl_ulong time_start, time_end;
cl_ulong total_time;

but when i compile the program mingw32-gcc makes this error :

format %lu expects argument of type 'long unsigned int' but argument 2 has type 'cl_ulong' 
[-Wformat]

and the *.exe does't run . so is there any body help me ? i am so confused about this error !!!


回答1:


cl_ulong is 64-bit unsigned on all platforms to match OpenCL C type ulong. It may differ from the C type 'unsigned long'. Try %llu in printf.




回答2:


cl_ulong is defined in cl_platform as:

typedef unsigned __int64 cl_ulong;

So %llu is correct. To make %llu work with mingw, add this line before your include files:

#define __USE_MINGW_ANSI_STDIO 1

Without this definition, you have to use the non-standard Microsoft equivalent, %I64u.



来源:https://stackoverflow.com/questions/17326819/printf-makes-error-and-dont-show-the-result

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!