Just a simple question,having this:
fftw_complex *H_cast;
H_cast = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*M*N);
what is the difference between:
H_cast= reinterpret_cast<fftw_complex*> (H);
and
H_cast= reinterpret_cast<fftw_complex*> (&H);
Thanks so much in advance
Antonio
Answer to current question
The difference is that they do two completely different things!
Note: you do not tell us what
His, so it’s impossible to answer the question with confidence. But general principles apply.For the first case to be sensible code,
Hshould be a pointer (typed asvoid*possibly?) to afftw_complexinstance. You would do this to tell the compiler thatHis really afftw_complex*, so you can then use it.For the second case to be sensible code,
Hshould be an instance of a class with a memory layout identical to that of classfftw_complex. I can’t think of a compelling reason to put yourself in this situation, it is very unnatural. Based on this, and since you don’t give us information regardingH, I think it’s almost certainly a bug.Original answer
The main difference is that in the second case you can search your source code for
reinterpret_cast(and hopefully ensure that every use is clearly documented and a necessary evil).However, if you are casting from
void*to another pointer type (is this the case here?) then it’s preferable to usestatic_castinstead (which can also be easily searched for).