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: Re: Re: Query for Empty Structure Extension.


Thanks James. I understood it now.

------- Original Message -------
Sender : James Dennett<james.dennett@gmail.com>
Date : Jan 04, 2013 05:28 (GMT+09:00)
Title : Re: Re: Query for Empty Structure Extension.

On Thu, Jan 3, 2013 at 11:35 AM, NAVEEN CHANDRAKAR <naveen.c@samsung.com> wrote:

Thanks for the quick reply.

As per the C++ standard (ISO/IEC 14882, 1998 first edition)

Section 9: Classes definition says.
Complete objects and member subobjects of class type shall have nonzero size.

Corrent me if i'm wrong here, but from this i had concluded empty object and structures are not part of C++ standard (or maybe my copy of standard is old).



I'm afraid you are indeed wrong.  The correct conclusion is that empty structures have nonzero size.

And they're implemented as part of GCC/G++ extension.

If so, then my question stands that how do we decide that a structure is empty ?

As per the definition of empty structures extension, should have size 1 byte in g++.
So what do we call structures which return size 0 in g++ ?

Eg:

struct T4
{long int:0;}t4;

//has size 1 in g++

whereas


struct T1
{struct{}a[0]; }t1;

//has size 0 in g++




That's a zero-sized array, which is a GCC extension.


-- James

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