Re:Porting to GCC 14: C language issues
by GrumpySloth on Monday February 19, 2024 @01:28PM
(#39433027)
No. It’s for tightly packing data in data structures. Bitwidth is exactly what’s important here.
[ Parent
| on HN ]
Re:Porting to GCC 14: C language issues
by Joker_vD on Monday February 19, 2024 @02:52PM
(#39433943)
Well, that's a shame because bitwidth of standard integer types is quite uncertain. CHAR_BIT can be (and is, on some platforms) 16 or 32, long was never guaranteed to be 64 bits (it's quite often was 32 bits on platforms with 16 bit ints) etc, not to mention that if that is what the standard integer types were for then they'd probably have names like int8/uint8/int16/int32/etc.
It's almost as if they were not, in fact, intended for precise control of bitwidths in portable manner...
Re:Porting to GCC 14: C language issues
by GrumpySloth on Monday February 19, 2024 @04:12PM
(#39434890)
It doesn’t matter what someone in the past thought they were for. That’s what they are for in practice, names are irrelevant here, yes, they are quite bad. But the ones in stdint.h are just typedefs for those, so that’s what we are left with.
Re:Porting to GCC 14: C language issues
by Joker_vD on Monday February 19, 2024 @09:43PM
(#39437458)
You can always use "unsigned char[N]" for that, you know, which is more realiable. You can even union it with an integer type for more convenient access, although please use static_assert to verify that the overlap is exact.
All in all, "it's very easy and straightforward to control the size and padding of a struct's fields in portable manner" is yet another C's imaginary advantage: it's not that straightforward or simple. The padding especially has always been a thorny issue.