public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/21361] New: sizeof() packed structs potential errors
@ 2005-05-03 15:10 moudekotte at khaeon dot nl
  2005-05-04 10:28 ` [Bug c++/21361] " moudekotte at khaeon dot nl
  0 siblings, 1 reply; 3+ messages in thread
From: moudekotte at khaeon dot nl @ 2005-05-03 15:10 UTC (permalink / raw)
  To: gcc-bugs

The following code produces different output in gcc4.0.0 and MSVC++7 .NET.
Additionally, I've tried 3.4.3 20050227 (Red Hat 3.4.3-22.fc3) and gcc 3.3.4
20040817 (Red Hat Linux 3.3.4-2), who all produce the same output as gcc4.0.0.

I'm unsure who is right here (don't know the exact C++ standards). If gcc4 is
right and MSVC++ is wrong this bug is invalid. 

CODE:
#include <stdio.h>

#define DEFSTR(name) \
	typedef struct name { \
		unsigned int var : 13; \
	};

#pragma pack(push, 1)
DEFSTR(pack1_struct)
#pragma pack(pop)

#pragma pack(push, 2)
DEFSTR(pack2_struct)
#pragma pack(pop)

#pragma pack(push, 4)
DEFSTR(pack4_struct)
#pragma pack(pop)

#pragma pack(push, 8)
DEFSTR(pack8_struct)
#pragma pack(pop)

#pragma pack(push, 16)
DEFSTR(pack16_struct)
#pragma pack(pop)

DEFSTR(unpacked_struct)

int main( int argc, char** argv ) {

	printf("sizeof(pack1_struct) = %u\n", sizeof(pack1_struct) );
	printf("sizeof(pack2_struct) = %u\n", sizeof(pack2_struct) );
	printf("sizeof(pack4_struct) = %u\n", sizeof(pack4_struct) );
	printf("sizeof(pack8_struct) = %u\n", sizeof(pack8_struct) );
	printf("sizeof(pack16_struct) = %u\n", sizeof(pack16_struct) );
	printf("sizeof(unpacked_struct) = %u\n", sizeof(unpacked_struct) );
	return 0;
}

PRODUCES ON GCC:
sizeof(pack1_struct) = 2
sizeof(pack2_struct) = 2
sizeof(pack4_struct) = 4
sizeof(pack8_struct) = 4
sizeof(pack16_struct) = 4
sizeof(unpacked_struct) = 4

PRODUCES ON MSVC++7:
sizeof(pack1_struct) = 4
sizeof(pack2_struct) = 4
sizeof(pack4_struct) = 4
sizeof(pack8_struct) = 4
sizeof(pack16_struct) = 4
sizeof(unpacked_struct) = 4

-- 
           Summary: sizeof() packed structs potential errors
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: moudekotte at khaeon dot nl
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: i686-redhat-linux
GCC target triplet: i386-redhat-linux


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


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

* [Bug c++/21361] sizeof() packed structs potential errors
  2005-05-03 15:10 [Bug c++/21361] New: sizeof() packed structs potential errors moudekotte at khaeon dot nl
@ 2005-05-04 10:28 ` moudekotte at khaeon dot nl
  0 siblings, 0 replies; 3+ messages in thread
From: moudekotte at khaeon dot nl @ 2005-05-04 10:28 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From moudekotte at khaeon dot nl  2005-05-04 10:27 -------
I noticed the PCC_BITFIELD_TYPE_MATTERS setting (hint:
http://www.astro.cf.ac.uk/cgi-bin/info2www?(gcc)Storage%20Layout ). I guess
packing settings overrule this PCC_BITFIELD_TYPE_MATTERS setting? If it was
meant to do so (and not just accidentally happened to do so), then please close
this bug. 

-- 


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


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

* [Bug c++/21361] sizeof() packed structs potential errors
       [not found] <bug-21361-10348@http.gcc.gnu.org/bugzilla/>
@ 2007-11-15 16:45 ` manu at gcc dot gnu dot org
  0 siblings, 0 replies; 3+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-11-15 16:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from manu at gcc dot gnu dot org  2007-11-15 16:45 -------
Closing then.

(The link you gave is broken. A more stable link is
 http://gcc.gnu.org/onlinedocs/gccint/Storage-Layout.html
)


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu dot org
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

end of thread, other threads:[~2007-11-15 16:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-03 15:10 [Bug c++/21361] New: sizeof() packed structs potential errors moudekotte at khaeon dot nl
2005-05-04 10:28 ` [Bug c++/21361] " moudekotte at khaeon dot nl
     [not found] <bug-21361-10348@http.gcc.gnu.org/bugzilla/>
2007-11-15 16:45 ` manu 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).