Question : Array to pointer?

The following works without any problems:

   fftw_complex *v;
   ...
   fftw_free(v);

but this kills my application:

   fftw_complex v[N];
   ...
   fftw_free(v);

The problem is occurring in the free() call which expects a pointer and not an array. I thought maybe passing &v instead would work, but it doesn't. What do I need to do?

Thanks!

P.S. I'm sure this is trivial, but I'm a Java programmer, and haven't completely gotten my head around pointers yet!

Answer : Array to pointer?

Hi InteractiveMind,

allthough ' fftw_complex v[N];' even instantiates a pointer to 'N' elements the pointer cannot be freed since it's allocated on the stack, not in the heap - you can only free pointers which you previosly allocate with 'alloc' (or related like 'calloc' or 'malloc') or 'new'.

So, you simply don't need to 'free' the 'v' in the second case ...

Hope that helps,

ZOPPO
Random Solutions  
 
programming4us programming4us