cutil.h and standard C C compile vs. C++ compile

Hello All,

For testing purposes I have some code which calls various CUDA functions that I would like to time. To keep things even, (I’m not just timing CUDA) I have a standard C main loop, and CUDA objects to call.

I like the cutil timing functions, so I call those in my main C function. This is fine if I compile my main C function with a C++ compiler, but not for a C compiler.

The problem stems from #include <cutil.h> and the enum CUTBoolean declaration at about line 64. I think the problem is because in C++

enum CUTBoolean { blah .. };

CUTBoolean this_function( ... );

is perfectly valid, but in C it isn’t - we get an error like this:

error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before

enum CUTBoolean this_function( ... );

is vaild C.

I can fix this by hacking cutil.h - I just use a

#ifndef __cplusplus

#  define CUTBOOL enum CUTBoolean


#  define CUTBOOL CUTBoolean

#endif /*__cplusplus*/

and then replace all CUTBoolean for CUTBOOL

But I don’t feel very happy with hacking the SDK. Does anyone have a better way around this? I like to keep my C functions pure C, and leave C++ out of it! Is cutil a plain old C friendly library?

Thanks for your help,


Edited to Add:

Sorry Mods, don’t want to cross post but I guess that I should have stuck this on the programming discussion board. Any chance it can get moved? Thanks

You should not be using cutil. It is there only to make SDK code cleaner and quicker to program. There are NO guarantees that NVIDIA won’t change cutil without warning and end up breaking all of your code.

I would suggest removing all references to cutil and use either Cuda Events or system time functions.

Thanks, but my problem was to do with calling C++ from C - after further code reading I’m resigned to using C++ for SDK work.

But I don’t get your fear of cutil.h - as it’s in the SDK it would obviously only be used for development code! SDK - software development kit…?

The SDK is a misnomer. It’s a set of examples. You should not be using cutil. It is like number two on my list of CUDA-related things that upset me because cutil is an abomination.

(in normal terms the toolkit is the software development kit and the SDK is a sample pack)

Cool, I understand a little more now, thanks.

BTW If that’s you’re number two, can you tell us what your number one is? ;-)