Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Size fo empty structs in C is zero byte. #782

Merged
merged 2 commits into from Apr 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/type-layout.md
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.
ldm0 marked this conversation as resolved.
Show resolved Hide resolved

#### \#[repr(C)] Unions

Expand Down