Variable has value in one function, and is 0 when passed to another?

Go To StackoverFlow.com

0

So my problem is, I am passing a variable by value (it is a float) from one function in my C code to another function. For some reason the variable is 0 after the pass. I have multiple other floats being passed by value, that are not 0 (all in the same function call), so I can't understand why this one is. It might be as simple as some typo that I am just not seeing:

int cuda_call(float *h_DataA, float *h_Kernel, int numSmooths, float kernelSum, int KERNEL_R, int KERNEL_W, int DATA_W){

    printf("\n What am I here?: %f \n", kernelSum);
    convolutionProgram(h_DataA, h_Kernel, numSmooths, kernelSum, KERNEL_R, KERNEL_W, DATA_W);
    return 1;
}

extern "C" void convolutionProgram(float *h_DataA, float *h_Kernel, int numSmooths, float kernelSum, int KERNEL_R, int KERNEL_W, int DATA_W);


void convolutionProgram(float *h_DataA, float *h_Kernel, int numSmooths, float kernelSum, int KERNEL_R, int KERNEL_W, int DATA_W){

    printf("\n what am I now? %f \n", kernelSum);
    float
        *d_DataA,
        *d_DataB,
        *d_Temp,
    *d_Kernel;
       .......
}

By the time I get to that second print in the called function, it is 0.

2012-04-05 18:39
by HillaryD
The methods are in two different files, hence the extern "C" thing - HillaryD 2012-04-05 18:42
you need to prototype the function first or it calls with arguments converted to integer - pizza 2012-04-06 03:26
Try not using extern c and compile the other function as c++ - P O'Conbhui 2012-04-13 00:38


1

Maybe you have somehow ended up mixing calling conventions (ABIs). For instance, the first compilation unit may be performing a cdecl call, while the second one is compiled with fastcall.

http://en.wikipedia.org/wiki/X86_calling_conventions

2012-04-05 19:29
by Roger Dahl


0

Is it possible that you have not rebuilt the object file for one of the c files? This looks like a signature mismatch which can arrise from a function signature change without rebuilding both object files.

2012-04-05 18:44
by tletnes
I thought that, maybe, but why would all the other values be right? numSmooths, KERNEL_R etc, are all correct values. In either case, I have rebuilt the object file a number of times - HillaryD 2012-04-05 18:45
Ads