need help to get bitoffsetof bitwidth for clang

Dakota dakota at gmail.com
Fri Jul 5 06:06:14 UTC 2024


On Wednesday, 3 July 2024 at 21:47:32 UTC, Tim wrote:
> If you only want to see the layout, you can use the following 
> command to dump it:
> ```
> clang test.c -Xclang -fdump-record-layouts -c
> ```
>
> File test.c could contain the following:
> ```
> struct S
> {
>     int a : 3;
>     int b : 29;
> };
> struct S dummy;
> ```
>
> The above clang command would then output:
> ```
> *** Dumping AST Record Layout
>          0 | struct S
>      0:0-2 |   int a
>     0:3-31 |   int b
>            | [sizeof=4, align=4]
> ```
>
> Inside a C/C++ program you could initialize a struct with all 
> 0xff, set one bitfield to zero and look at the bits. I have 
> used this to compare the bitfield layout between D and C++ in a 
> test added in https://github.com/dlang/dmd/pull/16590.

Thanks for the tips.

Then I guess there is no easy way to get equivalent in c for 
`bitoffsetof` and `bitwidth`




More information about the Digitalmars-d-learn mailing list