3 ms·
I once encountered a structured that were packed, even though it shouldn’t have been. Took me over a day to notice where the error came from. I was poking at th
by loup-vaillant 5y ago
I once encountered a structured that were packed, even though it shouldn’t have been. Took me over a day to notice where the error came from. I was poking at the internals of a library so I could gather information that it had, but did not provide. There was this context structure I normally only could access through a pointer, but copying the definition of the structure into my own code ought to do the trick…
…except it didn’t.
The way the library was compiled by default made the structure there smaller than my copy. Took me some time to guess why my data was all garbled, but the cause was pretty simple: there was no padding, even if it meant some members ended up unaligned. I had to replace the unaligned members by char arrays to get it to work (I did not dare explore the compilation options of the library).
And then I found a totally different solution for my problem. Oh well.