[cfe-dev] Flexible array members in a union
Reid Kleckner via cfe-dev
cfe-dev at lists.llvm.org
Wed Sep 8 13:08:31 PDT 2021
In this instance, clang appears to be doing MSVC-compatible struct layout.
See these examples on godbolt:
https://gcc.godbolt.org/z/3W47nTh8Y
MSVC will make this struct 8 bytes, GCC makes it 4. Clang follows suit
depending on the target, *-windows-gnu or *-windows-msvc. That seems like
intended behavior.
On Tue, Sep 7, 2021 at 1:56 PM Tal Shnaiderman via cfe-dev <
cfe-dev at lists.llvm.org> wrote:
> Hello,
>
> I hope this is the right forum for the question below.
>
> In the DPDK project we're using clang as the compiler on Windows.
>
> I noticed that there is a size difference between a Windows and a Linux if
> flexible array members are defined in a union inside a struct.
>
> e.g.
>
> struct umr {
> uint32_t temp;
> union {
> uint32_t res_dp[0];
> uint32_t res_dp2[0];
> };
> };
>
> On linux with GCC the result of
>
> sizeof(struct umr) = 4
>
> When on Windows with clang 11.0.0 I'm getting
>
> sizeof(struct umr) = 8
>
> Is this a bug? or flexible array members in a union behavior is undefined?
>
> Thanks
>
> Tal Shnaiderman.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20210908/2060a35a/attachment.html>
More information about the cfe-dev
mailing list