From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14911 invoked by alias); 17 Jan 2002 04:14:58 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 14794 invoked from network); 17 Jan 2002 04:14:52 -0000 Received: from unknown (HELO thalia.fm.intel.com) (132.233.247.11) by sources.redhat.com with SMTP; 17 Jan 2002 04:14:52 -0000 Received: from fmsmsxvs042.fm.intel.com (fmsmsxv042-1.fm.intel.com [132.233.48.110]) by thalia.fm.intel.com (8.9.1a+p1/8.9.1/d: relay.m4,v 1.48 2001/12/13 16:27:50 root Exp $) with SMTP id EAA18371 for ; Thu, 17 Jan 2002 04:14:51 GMT Received: from milikk.co.intel.com ([10.10.213.18]) by fmsmsxvs042.fm.intel.com (NAVGW 2.5.1.16) with SMTP id M2002011620165725616 for ; Wed, 16 Jan 2002 20:16:57 -0800 Received: from inaky by milikk.co.intel.com with local (Exim 3.33 #1 (Debian)) id 16R3oZ-0001Ia-00 for ; Wed, 16 Jan 2002 20:06:11 -0800 To: gcc-help@gcc.gnu.org From: inaky.gonzalez@intel.com Subject: Differences in struct size when compiling C vs. C++ Message-Id: Date: Wed, 16 Jan 2002 20:14:00 -0000 X-SW-Source: 2002-01/txt/msg00171.txt.bz2 Hi people Tried this with gcc and g++ versions 2.95.4 and 3.0.3. I am looking for some enlightment on why the struct's sizes are so wildly different in C and in C++: Compile with gcc: $ gcc kk.c -o kk -Wall output is: sizeof (struct A) 4, sizeof (struct B) 0 now with G++: $ 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 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; } -- naky @ somewhere in time -- e-ssing PQ even++