Skip to content

Commit

Permalink
Merge pull request #782 from ldm0/master
Browse files Browse the repository at this point in the history
Size fo empty structs in C is zero byte.
  • Loading branch information
Centril authored Apr 2, 2020
2 parents 89dd146 + 30af091 commit 8e7e6a0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/type-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,12 @@ the sake of clarity. To perform memory layout computations in actual code, use

</div>

> Note: This algorithm can produce zero-sized structs. This differs from
> C where structs without data still have a size of one byte.
> Note: This algorithm can produce zero-sized structs. In C, an empty struct
> declaration like `struct Foo { }` is illegal. However, both gcc and clang
> support options to enable such structs, and assign them size zero. C++, in
> contrast, gives empty structs a size of 1, unless they are inherited from or
> they are fields that have the `[[no_unique_address]]` attribute, in which
> case they do not increase the overall size of the struct.
#### \#[repr(C)] Unions

Expand Down

0 comments on commit 8e7e6a0

Please sign in to comment.