Function that return a pointer to dim3 variable. Is it actually possible to make a function with ret

Hi,

I want to make a function with this interface

dim3* getGridSize( int size );

How can I allocate a dim3 variable and return its address?

Note:

I tryed

dim3* getGridSize( int size){

dim3 *gd=(dim3*)new(dim3);

    [...]

return gd;

}

and

dim3* getGridSize( int size){

dim3 *gd=NULL;

    gd=(dim3*)malloc(sizeof(dim3));

    [...]

return gd;

}

but compiler said:

error: expression must have class type

Any suggestion pls?

void GetSize( dim3 &myGrid )

{

  myGrid.x = ...;

  myGrid.y = ...;

}

....

void main( )

{

   dim3 grid;

   GetSize( grid );

   ...

}

Just tried a quick one myself. This works without a problem.

// inside my cuda file (somefile.cu)

extern "C"

dim3* getDimPtr(int x, int y, int z)

{

	dim3* threads = new dim3(x, y, z);

	return threads;

}

//inside my main.cpp file

extern "C" dim3* getDimPtr(int x, int y, int z); // at the top

// elsewhere in the main.cpp file

dim3* dp = getDimPtr(1, 2, 3);

cout<< dp->x <<" "<< dp->y <<" "<< dp->z <<endl;

thanks a lot