This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Re: Re: Query for Empty Structure Extension.
- From: NAVEEN CHANDRAKAR <naveen dot c at samsung dot com>
- To: James Dennett <james dot dennett at gmail dot com>
- Cc: Jonathan Wakely <jwakely dot gcc at gmail dot com>, "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Fri, 04 Jan 2013 06:01:34 +0000 (GMT)
- Subject: Re: Re: Re: Query for Empty Structure Extension.
- Dlp-filter: Pass
- Msgkey: 20130104055945467@naveen.c
- Reply-to: naveen dot c at samsung dot com
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