2

I am working with a C/C++ FFT library that takes an array of floats as argument. In particular, the routines take an array of 2N floats as argument. I.e., in order to do a N points FFT you pass 2N floats (real and imaginary part of each point).

If I am working with an array of elements of type std::complex<float>, can I pass this array as argument to the FFT routines? What's the in memory layout of each element? Two floats or something else? Would it be safe?

jbgs
  • 2,795
  • 2
  • 21
  • 28
  • 2
    @Mgetz: No, it will always work. See [here](http://stackoverflow.com/a/5020268/133374). – Albert Mar 01 '14 at 12:39
  • So it will always work according to C++11 standard, right? – jbgs Mar 01 '14 at 12:40
  • @Mgetz: the C++11 standard explicitly guarantees that this kind of access will work (also it is not clear why the compiler should pad an array of a POD class composed by two `float` differently than an array of `float`). – Matteo Italia Mar 01 '14 at 12:46
  • @Mgetz Please read C++0x standard sections §26.4 and §23.3.6 (you can see quotes of them [here](http://stackoverflow.com/questions/5020076/passing-a-c-complex-array-to-c)). The standard is worded in such a way that the compiler is *required* to make this work, regardless of padding/alignment requirements. – TypeIA Mar 01 '14 at 13:41
  • @dvnrrs ah... interestingly enough... only for `std::complex` though as best I can tell (at least according to N3337) – Mgetz Mar 01 '14 at 13:50

1 Answers1

1

It's two floats, so you can just cast it. See here.

Community
  • 1
  • 1
Albert
  • 65,406
  • 61
  • 242
  • 386