Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

More than one instance overloaded function has C linkage

Tags:

c++

cuda

Following the sample code in CUDA samples about C++ integration I was writing the wrapper functions that call CUDA code in a .cu file.

In that file I have a function that initializes CUDA context and allocates global memory and puts some data in constant memory.

extern "C" void initEngine(int *d_data, int *d_coefA, int *d_coefB)
{
   //Allocations
   //Copy to constant memory
}

Now what I want to do is overload that initEngine function to receive to more parameters but I think there's no way to overload that function as it has C linkage am I right?

extern "C" void initEngine(int *d_data, int *d_coefA, int *d_coefB, int *d_coefC, 
                           int *d_random)
{
   //Allocations
   //Copy to constant memory
}

Could you give me some advise to have only one initEngine function? or is not possible and I have to have 2 functions or probably have only one function with all the parameters and just pass NULL references or something like that.

like image 601
BRabbit27 Avatar asked Sep 07 '25 05:09

BRabbit27


1 Answers

Yes, overloading is a C++ feature.

If you want to have overloaded functions that are callable from other modules, use C++ throughout (i.e. don't use extern "C", and keep all your files as .cpp or .cu).

If you don't wish to do that, you could try resorting to macros or some other magic.

like image 198
Robert Crovella Avatar answered Sep 09 '25 00:09

Robert Crovella