public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrea 'Fyre Wyzard' Bocci <fwyzard@inwind.it>
To: inaky.gonzalez@intel.com,gcc-help@gcc.gnu.org
Subject: Re: Differences in struct size when compiling C vs. C++
Date: Thu, 17 Jan 2002 04:20:00 -0000	[thread overview]
Message-ID: <5.1.0.14.0.20020117131026.027646f8@popmail.inwind.it> (raw)
In-Reply-To: <E16R3oZ-0001Ia-00@milikk.co.intel.com>

At 20.06 16/01/2002 (GMT -0800), inaky.gonzalez@intel.com wrote:

>$ gcc kk.c -o kk -Wall
>
>output is:
>   sizeof (struct A) 4, sizeof (struct B) 0
>
>$ g++ kk.c -o kk -Wall
>
>output is:
>   sizeof (struct A) 8, sizeof (struct B) 1
>
>
>Why? :) I would expect this if there were vtables around, but I am
>afraid there aren't any. Can anybody give me some insight? [pls copy
>me, as I am not subscribed to the list]
>
>     Thanks!
>
>PS: Great compiler, though :)
>
>
>-- begin kk.c...
>
>#include <stdio.h>
>
>struct A
>{
>   int d;
>   struct {} c;
>};
>
>struct B
>{
>   struct
>   {
>   } c;
>};
>
>int main (void)
>{
>   printf ("sizeof (struct A) %d, sizeof (struct B) %d\n",
>           sizeof (struct A), sizeof (struct B));
>   return 0;
>}

I think this is the same as in issue discussed a month ago on the gcc ML 
for classes (http://gcc.gnu.org/ml/gcc/2001-12/msg00836.html).
Shortly:
The empty struct sub-object must have a different address from the struct 
that contains it.
This is obvious with A, where "int d" between the two makes this happen 
automatically.
With B, the compiler must use an empty byte to let the struct {} c addres 
be different from that of B.
Then everything is alligned to 32 bit boundaries.
Well - I don't know why this doesn't happen with plai gcc. Maybe C doesn't 
need to keep the addresses different ?

HTH
fwyzard

  reply	other threads:[~2002-01-17 12:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-01-16 20:14 inaky.gonzalez
2002-01-17  4:20 ` Andrea 'Fyre Wyzard' Bocci [this message]
2002-01-22 12:20 Gonzalez, Inaky
     [not found] <13FCCC1F3509D411B1C700A0C969DEBB05E20D01@fmsmsx91.fm.intel .com>
2002-01-22 13:09 ` Andrea 'Fyre Wyzard' Bocci

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5.1.0.14.0.20020117131026.027646f8@popmail.inwind.it \
    --to=fwyzard@inwind.it \
    --cc=gcc-help@gcc.gnu.org \
    --cc=inaky.gonzalez@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).