public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/17173] New: layout of bitfields with larger-than-int base type
@ 2004-08-24 20:01 terra at gnome dot org
2004-08-24 20:14 ` [Bug c/17173] " terra at gnome dot org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: terra at gnome dot org @ 2004-08-24 20:01 UTC (permalink / raw)
To: gcc-bugs
The program below prints 8, 4 for me.
>From http://www.open-std.org/jtc1/sc22/wg14/www/docs/n869/n869.txt.gz
we have...
[#10] A bit-field declaration with no declarator, but only a
colon and a width, indicates an unnamed bit-field.96) As a
special case, a bit-field structure member with a width of 0
indicates that no further bit-field is to be packed into the
unit in which the previous bit-field, if any, was placed.
My reading of this is that Foo1 and Foo2 should be laid out identically
and that the claimed type for ":0" fields is irrelevant. The type of
the *previous* unit is what matters.
We obviously have a least one leg into implementation-defined territory.
-----------------------------------------------------------------------------
#include <stddef.h>
#include <stdio.h>
typedef int s;
int
main (int argc, char **argv)
{
struct Foo1 {
int : 1;
unsigned long long int : 0;
int z;
};
struct Foo2 {
int : 1;
int : 0;
int z;
};
printf ("%d\n", offsetof (struct Foo1, z));
printf ("%d\n", offsetof (struct Foo2, z));
return 0;
}
--
Summary: layout of bitfields with larger-than-int base type
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: terra at gnome dot org
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: sparc-sun-solaris2.8
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17173
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/17173] layout of bitfields with larger-than-int base type
2004-08-24 20:01 [Bug c/17173] New: layout of bitfields with larger-than-int base type terra at gnome dot org
@ 2004-08-24 20:14 ` terra at gnome dot org
2004-08-24 20:28 ` pinskia at gcc dot gnu dot org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: terra at gnome dot org @ 2004-08-24 20:14 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From terra at gnome dot org 2004-08-24 20:14 -------
With this...
struct Foo3 {
int : 1;
int : 0;
unsigned long long int : 0;
int z;
};
...things get clearer: the second :0 field should do nothing as the previous
unit has already been closed off. It should therefore print 4 (as Foo2), but
it prints 8 for me.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17173
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/17173] layout of bitfields with larger-than-int base type
2004-08-24 20:01 [Bug c/17173] New: layout of bitfields with larger-than-int base type terra at gnome dot org
2004-08-24 20:14 ` [Bug c/17173] " terra at gnome dot org
@ 2004-08-24 20:28 ` pinskia at gcc dot gnu dot org
2004-08-24 23:34 ` jsm at polyomino dot org dot uk
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-08-24 20:28 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-08-24 20:28 -------
Reading: <http://gcc.gnu.org/onlinedocs/gcc/Structures-unions-enumerations-and-bit_002dfields-
implementation.html#Structures-unions-enumerations-and-bit_002dfields-implementation>, I think
this is an ABI issue rather than a compiler one really.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17173
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/17173] layout of bitfields with larger-than-int base type
2004-08-24 20:01 [Bug c/17173] New: layout of bitfields with larger-than-int base type terra at gnome dot org
2004-08-24 20:14 ` [Bug c/17173] " terra at gnome dot org
2004-08-24 20:28 ` pinskia at gcc dot gnu dot org
@ 2004-08-24 23:34 ` jsm at polyomino dot org dot uk
2004-08-27 6:27 ` pinskia at gcc dot gnu dot org
2004-08-31 11:12 ` ebotcazou at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: jsm at polyomino dot org dot uk @ 2004-08-24 23:34 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From jsm at polyomino dot org dot uk 2004-08-24 23:34 -------
Subject: Re: New: layout of bitfields with larger-than-int base
type
On Tue, 24 Aug 2004, terra at gnome dot org wrote:
> struct Foo1 {
> int : 1;
> unsigned long long int : 0;
> int z;
> };
Note that the documented implementation-defined behavior is that no
implementation-defined bit-field types such as unsigned long long int are
permitted in strictly conforming mode. That said, there is a comment
@c Would it be better to restrict the pedwarn for other types to C90
@c mode and document the other types for C99 mode?
and this may change. However, as the size and alignment of the
addressable storage unit holding bit-fields are unspecified or
implementation-defined, I see no problem with the type of a :0 bit-field
being relevant to the layout. The layout depends on the ABI and the
question of whether this is the correct layout needs to be referred to any
applicable ABI for the target in question.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17173
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/17173] layout of bitfields with larger-than-int base type
2004-08-24 20:01 [Bug c/17173] New: layout of bitfields with larger-than-int base type terra at gnome dot org
` (2 preceding siblings ...)
2004-08-24 23:34 ` jsm at polyomino dot org dot uk
@ 2004-08-27 6:27 ` pinskia at gcc dot gnu dot org
2004-08-31 11:12 ` ebotcazou at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-08-27 6:27 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-08-27 06:27 -------
The ABI says what the layout should be, if this is an ABI bug, please reopen it then but I really doubt it.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17173
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/17173] layout of bitfields with larger-than-int base type
2004-08-24 20:01 [Bug c/17173] New: layout of bitfields with larger-than-int base type terra at gnome dot org
` (3 preceding siblings ...)
2004-08-27 6:27 ` pinskia at gcc dot gnu dot org
@ 2004-08-31 11:12 ` ebotcazou at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: ebotcazou at gcc dot gnu dot org @ 2004-08-31 11:12 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From ebotcazou at gcc dot gnu dot org 2004-08-31 11:12 -------
For the sake of completeness, the ABI as defined by the SCD 2.4.1 says that
'unsigned long long int' is 8-byte aligned on SPARC 32-bit.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17173
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2004-08-31 11:12 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-24 20:01 [Bug c/17173] New: layout of bitfields with larger-than-int base type terra at gnome dot org
2004-08-24 20:14 ` [Bug c/17173] " terra at gnome dot org
2004-08-24 20:28 ` pinskia at gcc dot gnu dot org
2004-08-24 23:34 ` jsm at polyomino dot org dot uk
2004-08-27 6:27 ` pinskia at gcc dot gnu dot org
2004-08-31 11:12 ` ebotcazou 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).