This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: zero sized structs


On Wed, Nov 12, 2008 at 03:52:01PM -0800, Joe Buck wrote:
> 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.

Unfortunately fixing this would change the ABI, so we might be stuck
with it.




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]