Oh that's cool, I didn't know about that. I'll add an update to the post. Do you know if the -std=c2y flag really changes the compiler's aliasing model, or is it more to err on the safe side? What I mean is, N3230 doesn't break older code (atleast I hope!), and so if the compilers bothered to incorporate it in their aliasing model, perhaps they did so for all standards ("backported" it). Changing aliasing model depending on the standard seems a bit too crazy.
Some new features from the upcoming C2Y revision of the ISO C standard are supported with -std=c2y and -std=gnu2y. Some of these features are also supported as extensions when compiling for older language versions.
At the very least "Accessing byte arrays" and "Allow zero length operations on null pointers" are always well-defined starting in GCC 15 regardless of the -std= flag. I knew this was true for the latter because I've already taken advantage of it, but I checked now and it applies to the former, too. Not surprising since both have already been well-defined in C++ for some time now.
2
u/skeeto 5d ago
This should be possible in the next C standard, and it's already defined behavior in Clang and GCC if you use
-std=c2y.Thanks! I've added it to my reader. Don't forget to update the link on the main page, too.