When trying to debug the problem that I use Speex with, I noticed that it (well, not only speex, but also the sample code) does the following:
- Returns a pointer to EncState from the initialization function.
- Insert this pointer into a void pointer
- Save void pointer
- (in the other place)
- Place void pointer to pointer to pointer to SpeexMode
- Split pointer
It so happened that the EncState definition begins with a field of type SpeexMode *, so the integer values โโof the pointer to the first field and the pointer to the structure are the same. The gap occurs at runtime.
But ... does this language really allow this? Is the compiler free to do whatever it wants if it compiles it? Throws the structure T * into the behavior of the structure C * undefined if the first field T is C?
source
share