[cfe-dev] Flexible array members in a union
Reid Kleckner via cfe-dev
cfe-dev at lists.llvm.org
Fri Sep 10 10:16:52 PDT 2021
MSVC assigns the union a sizeof 4, and GCC assigns it a size of zero, and I
think that's all there is to it:
https://gcc.godbolt.org/z/1nhscrve9
I think if you drill down, GCC is allowing this union to be zero-sized, but
MSVC ensures that the size is non-zero, and then rounds the size up to
alignment to get 4.
On Fri, Sep 10, 2021 at 9:58 AM Tal Shnaiderman <talshn at nvidia.com> wrote:
> Thank you for the information, any idea why this difference exists?
>
>
>
> I only found this in C11:
>
>
>
> “In most situations, the flexible array member is ignored. In particular,
> the size of the structure is as if the flexible array member were omitted
> except that it may have more trailing padding than the omission would imply”
>
If ignoring the flexible array elements results in an empty record, the
empty record would normally get a size of 1. GCC seems to have some special
rules here that MSVC does not.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20210910/c22ec4ea/attachment.html>
More information about the cfe-dev
mailing list