From 30af09147d38d63aed24a7d707df9aeb5524d5b2 Mon Sep 17 00:00:00 2001 From: Donough Liu Date: Fri, 13 Mar 2020 21:55:21 +0800 Subject: [PATCH] Further improvement --- src/type-layout.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/type-layout.md b/src/type-layout.md index 003a3ce63..7557d951c 100644 --- a/src/type-layout.md +++ b/src/type-layout.md @@ -236,9 +236,12 @@ the sake of clarity. To perform memory layout computations in actual code, use -> Note: This algorithm can produce zero-sized structs. In C, the size of -> structs without data is zero. This is not the same as 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