public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/26178]  New: sizeof still fails calculating size of an structure (sizeof(struct my_struct))
@ 2006-02-08 17:21 chrisnaak at yahoo dot com
  2006-02-08 17:23 ` [Bug c++/26178] " pinskia at gcc dot gnu dot org
  2006-02-08 17:23 ` pinskia at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: chrisnaak at yahoo dot com @ 2006-02-08 17:21 UTC (permalink / raw)
  To: gcc-bugs

Request to REOPEN bug 6385 was DENIED... creating a new bug...
Error previously reported on bug 6385 (against version 3.0.4.) persists in
version 3.4.4. for more elaborated structs, example:
struct bug_struct {
   short a, b, c, d, e, f, g, h, i, j, k, l;
   char m[8];
   float n, o, p, q, r;
   short s;
   char t[20], u[20];
   char v[8];
};
is evaluated as 104 bytes (should be 102).
Following program returns 1:
--------------------------------------------------------------------------------
struct bug_struct {
   short a, b, c, d, e, f, g, h, i, j, k , l;
   char m[8];
   float n, o, p, q, r;
   short s;
   char t[20], u[20];
   char v[8];
};

bug_struct bug;
long int a, b;

const char *explain1 = "The structure above defined is 102 bytes long.";
const char *explain2 = "'a' receives the size of all individual parts: 102.";
const char *explain3 = "'b' receives the size of the struct: 104.";
const char *explain4 = "Program retuns 1.";

int main(void) {
   a = sizeof(bug.a)+sizeof(bug.b)+sizeof(bug.c)+sizeof(bug.d)+
       sizeof(bug.e)+sizeof(bug.f)+sizeof(bug.g)+sizeof(bug.h)+
       sizeof(bug.i)+sizeof(bug.j)+sizeof(bug.k)+sizeof(bug.l)+
       sizeof(bug.m)+sizeof(bug.n)+sizeof(bug.o)+sizeof(bug.p)+
       sizeof(bug.q)+sizeof(bug.r)+sizeof(bug.s)+sizeof(bug.t)+
       sizeof(bug.u)+sizeof(bug.v);
   b = sizeof(bug);
   if (a == b)
      return 0;
   else
      return 1;
}
--------------------------------------------------------------------------------
 * Diagnostic dumps:
 * -----------------

OUTPUT FROM "g++ -v": 
Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs
Configured with: /gcc/gcc-3.4.4/gcc-3.4.4-1/configure --verbose --prefix=/usr
--exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libexecdir=/usr/lib
--mandir=/usr/share/man --infodir=/usr/share/info
--enable-languages=c,ada,c++,d,f77,java,objc --enable-nls
--without-included-gettext --enable-version-specific-runtime-libs --without-x
--enable-libgcj --disable-java-awt --with-system-zlib --enable-interpreter
--disable-libgcj-debug --enable-threads=posix --enable-java-gc=boehm
--disable-win32-registry --enable-sjlj-exceptions --enable-hash-synchronization
--enable-libstdcxx-debug : (reconfigured) 
Thread model: posix
gcc version 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)

OUTPUT FROM "g++ -x c++ -Wall -save-temps bug-sizeof.c++ -o bug-sizeof.exe":
<none>

OUTPUT FROM "uname -a":
CYGWIN_NT-5.1 ME109APC3 1.5.18(0.132/4/2) 2005-07-02 20:30 i686 unknown unknown
Cygwin

OUTPUT FROM "./bug-sizeof.exe; echo $?"
1


-- 
           Summary: sizeof still fails calculating size of an structure
                    (sizeof(struct my_struct))
           Product: gcc
           Version: 3.4.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: chrisnaak at yahoo dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26178


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/26178] sizeof still fails calculating size of an structure (sizeof(struct my_struct))
  2006-02-08 17:21 [Bug c++/26178] New: sizeof still fails calculating size of an structure (sizeof(struct my_struct)) chrisnaak at yahoo dot com
  2006-02-08 17:23 ` [Bug c++/26178] " pinskia at gcc dot gnu dot org
@ 2006-02-08 17:23 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-02-08 17:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2006-02-08 17:23 -------
There is padding in this struct which is why the size is different than from
the sum of all the parts.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26178


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/26178] sizeof still fails calculating size of an structure (sizeof(struct my_struct))
  2006-02-08 17:21 [Bug c++/26178] New: sizeof still fails calculating size of an structure (sizeof(struct my_struct)) chrisnaak at yahoo dot com
@ 2006-02-08 17:23 ` pinskia at gcc dot gnu dot org
  2006-02-08 17:23 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-02-08 17:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-02-08 17:23 -------
Not a bug - you don't appear to understand padding
    and alignment requirements.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26178


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-02-08 17:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-08 17:21 [Bug c++/26178] New: sizeof still fails calculating size of an structure (sizeof(struct my_struct)) chrisnaak at yahoo dot com
2006-02-08 17:23 ` [Bug c++/26178] " pinskia at gcc dot gnu dot org
2006-02-08 17:23 ` pinskia at gcc dot gnu dot org

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).