If payload was ever dereferenced as a char array as well, I would buy the strict aliasing argument. But it’s not, it exists as a char pointer solely for pointer arithmetic.
AFAIK The purpose of strict aliasing rules is to let the compiler assume that dereferencing pointers of different types never refer to the same memory.
If ISO C treats this as UB, shouldn’t ISO C be fixed?
I’m not chasing theoretical portability and checking off a box saying my code is 100% pure ISO C. If that’s important to you, don’t do this (and also don’t use pretty much any allocator!)
Every sufficiently useful C codebase assumes specific implementations.
Comments
If payload was ever dereferenced as a char array as well, I would buy the strict aliasing argument. But it’s not, it exists as a char pointer solely for pointer arithmetic.
AFAIK The purpose of strict aliasing rules is to let the compiler assume that dereferencing pointers of different types never refer to the same memory.
If ISO C treats this as UB, shouldn’t ISO C be fixed?
No, you should fix your code to be compliant with ISO C. The optimizer isn’t going to wait for you to convince WG14.
I’m not chasing theoretical portability and checking off a box saying my code is 100% pure ISO C. If that’s important to you, don’t do this (and also don’t use pretty much any allocator!)
Every sufficiently useful C codebase assumes specific implementations.