2 ms·
yes, though you can fix that with compiler flags (or, #pragma if you want strict aliasing elsewhere in your code) alternatively, gcc supports VLAs in unions, b
by cozzyd 3y ago
yes, though you can fix that with compiler flags (or, #pragma if you want strict aliasing elsewhere in your code)
alternatively, gcc supports VLAs in unions, but I don't think clang does, but that makes it extra annoying to do.
edit: apparently you can probably apply the may_alias attribute to the type? Or you could try using transparent_union. No idea if clang supports either...
- mananaysiempre 3y agoAt that point, it is IMO better to obtain that block from alloca()[1]—it’s not standard, but where it’s available the compiler will treat the result as untyped for the purposes of aliasing. (If you’re on GCC/LLVM, __builtin_alloca_with_align is also an option, although note that the memory it returns may not outlive the current block—similar to a standard automatic variable, but unlike memory from traditional alloca.) ISO C has a gigantic hole when it comes to obtaining and recycling untyped memory, pretending the hole is not there isn’t going to help. [1] https://nullprogram.com/blog/2019/10/28/ https://nullprogram.com/blog/2019/10/28/, discussed at the time at https://news.ycombinator.com/item?id=21374863 https://news.ycombinator.com/item?id=21374863