Warning when returning local address in non kernel function...

Hi all,

Here is a sample …

double* foo () {

double result_reg[2];
    result_reg[0] = ...
    result_reg[1] = ...
return result_reg;

}

I am not sure the content of result will not be erased, when exiting from foo(). Am I right, or is there a function address space like stack in C?
Many thanks!

This is problematic in OpenCL C as well regular C. The data contained in result_reg[] should be considered invalid when the function returns. So there’s no legitimate purpose for returning a pointer to it from a function.

Just pass the pointer in as an arg

Ok, many thanks to all!