3 ms·
> Struct padding? Implementation-defined. Bit field implementation? So implementation-defined you'll have to roll your own with shifts and masks. You must be m
by SV_BubbleTime 6y ago
> Struct padding? Implementation-defined. Bit field implementation? So implementation-defined you'll have to roll your own with shifts and masks.
You must be much more advanced than I am. Because in 20 years I’ve never had an issue with structure padding because I just assume it pads to n basetypes and pad them manually to 4byte intervals in 32bit.
As to portability, man, you must be moving from ARM to mips to x86 to 8051 to OLD stuff, I’ve never had an issues here either, I just don’t make assumptions of but order if it might matter. Jh mean, code gets tested right? LE to BE or padding or whatever isn’t going to slip by me typically.
The problem with shifts and masks is they don’t typically “automatically” take advantage of the BMF cpu operations like structures definitely will.
IDK, like I said, you must be more advanced than I am. I’ve had none of this issues. Ignorance must be bliss! :)
- oriolid 6y agoYes, my most interesting experience is from writing code that was portable between to TI DSPs. One had 16-bit char and 24-bit pointer, the other 8 and 32 bits. Of course, the struct padding, bit field packing, char signedness, etc were also different. By the way, their compilers were very good at two things: optimizing shifts and masks into bit access operations and sticking to the standard where it is the least intuitive. C was originally intended to be a high level systems programming language and this stuff would have been written in assembly, and it shows.