This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: zero sized structs
- From: Joe Buck <Joe dot Buck at synopsys dot COM>
- To: nadult <nadult at gmail dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Wed, 12 Nov 2008 15:52:01 -0800
- Subject: Re: zero sized structs
- References: <491B6564.1000902@gmail.com>
On Thu, Nov 13, 2008 at 12:23:16AM +0100, nadult wrote:
> Hello, i have some problems with empty (almost) structures containing
> zero-sized arrays:
>
> struct Zero { int value[0]; };
> int main() {
> std::cout << "sizeof(Zero)==" << sizeof(Zero) << '\n';
> return 0;
> }
>
> The output i get for every g++ i compile it on is:
> sizeof(Zero)==0
Zero-sized arrays aren't allowed in standard C++.
However, I think that this result is a bug, because g++ will normally
ensure the size is at least one, so that each object in an array
(or a struct/class with multiple instances of the same object) have
distinct addresses.
> Is this a bug, or maybe zero-sized arrays are gcc extension not fully
> supported in g++?
Both, I think.