[llvm-dev] Struct padding

Jonas Devlieghere via llvm-dev llvm-dev at lists.llvm.org
Thu May 18 00:47:42 PDT 2017


Hi Hongbin,

You can pass `-Wpadded` to clang. For your particular example it will print
something along the lines of

```
warning: padding struct 'foo1' with 7 bytes to align 'x' [-Wpadded]
    long x;
```

Jonas

On Thu, May 18, 2017 at 9:15 AM, Hongbin Zheng via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hi,
>
> I am wondering how I can tell whether a field of a struct is introduced by
> padding or not.
>
> For example, if I have a struct:
>
> struct foo1 {
>     char *p;     /* 8 bytes */
>     char c;      /* 1 byte
>     long x;      /* 8 bytes */
> };
>
> clang may generate:
>
> struct foo1 {
>     char *p;     /* 8 bytes */
>     char c;      /* 1 byte
>     char pad[7]; /* 7 bytes */
>     long x;      /* 8 bytes */
> };
>
> Is there any way that I can tell the "pad" array is generated by padding?
>
> Thanks a lot
> Hongbin
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170518/de746f41/attachment-0001.html>


More information about the llvm-dev mailing list