From: "Martin v. Loewis" <martin@mira.isdn.cs.tu-berlin.de>
To: greened@eecs.umich.edu
Cc: egcs@egcs.cygnus.com
Subject: Re: egcs and bitfields
Date: Wed, 31 Mar 1999 23:46:00 -0000 [thread overview]
Message-ID: <199903121718.SAA09252@mira.isdn.cs.tu-berlin.de> (raw)
Message-ID: <19990331234600.rkRbdz2F3dTJa6WkBU692T-7hSHD_SHxmMVhEW9btMQ@z> (raw)
In-Reply-To: <36E92F61.5951621@eecs.umich.edu>
> #include <stdio.h>
>
> struct foo { int c:3; } x = { 7 };
>
> int main(void)
> {
> printf("%d\n", x.c);
>
> return(0);
> }
Ok, I can reproduce this printing -1. Yet, it still took me a while to
understand the problem. If you had provided proper references and
quotes, that would have been nice... Here's what I found:
The C standard explicitly leaves it unspecified whether an int
bitfield is signed or unsigned. In draft C9x, 6.7.2/5 says
>> Each of the comma-separated sets designates the same type, except
>> that for bit-fields, it is implementation-defined whether the
>> specifier int designates the same type as signed int or the same
>> type as unsigned int.
Now, the gcc documentation says, in the command-line-flags section,
`-fsigned-bitfields'
`-funsigned-bitfields'
`-fno-signed-bitfields'
`-fno-unsigned-bitfields'
These options control whether a bitfield is signed or unsigned,
when the declaration does not use either `signed' or `unsigned'.
By default, such a bitfield is signed, because this is consistent:
the basic integer types such as `int' are signed types.
However, when `-traditional' is used, bitfields are all unsigned
no matter what.
Indeed, when I compile your program with -funsigned-bitfields, it
gives the output '7', on i586-pc-linux-gnu.
Please have a look at the section 'Non-bugs' in the GCC manual. It
explains, in an elaborate way, why things are the way they are (and
yes, I've read this section for the first time today :-)
If you still think there is a bug, please make a detailed report to
egcs-bugs@cygnus.com. I think in this case, such a report should also
go to gcc-bugs@gnu.org.
Regards,
Martin
next prev parent reply other threads:[~1999-03-31 23:46 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-03-11 14:33 David A. Greene
[not found] ` < 36E844B2.8DAEFAAF@eecs.umich.edu >
1999-03-11 15:14 ` Martin v. Loewis
[not found] ` < 199903112300.AAA19947@mira.isdn.cs.tu-berlin.de >
1999-03-11 15:41 ` Robert Lipe
1999-03-31 23:46 ` Robert Lipe
1999-03-12 7:16 ` David A. Greene
[not found] ` < 36E92F61.5951621@eecs.umich.edu >
1999-03-12 8:48 ` Robert Lipe
[not found] ` < 19990312104540.D1570@rjlhome.sco.com >
1999-03-12 9:41 ` Doug Semler
[not found] ` < 199903121741.JAA24401@vortex.seaspace.com >
1999-03-12 9:59 ` Robert Lipe
1999-03-31 23:46 ` Robert Lipe
1999-03-12 13:26 ` Martin v. Loewis
[not found] ` < 199903122118.WAA00520@mira.isdn.cs.tu-berlin.de >
1999-03-12 13:52 ` Doug Semler
1999-03-31 23:46 ` Doug Semler
1999-03-31 23:46 ` Martin v. Loewis
1999-03-31 23:46 ` Doug Semler
1999-03-31 23:46 ` Robert Lipe
1999-03-12 9:27 ` Martin v. Loewis [this message]
1999-03-12 10:47 ` David A. Greene
1999-03-31 23:46 ` David A. Greene
1999-03-31 23:46 ` Martin v. Loewis
1999-03-31 23:46 ` David A. Greene
1999-03-31 23:46 ` Martin v. Loewis
1999-03-31 23:46 ` David A. Greene
1999-03-12 7:20 David A. Greene
1999-03-31 23:46 ` David A. Greene
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=199903121718.SAA09252@mira.isdn.cs.tu-berlin.de \
--to=martin@mira.isdn.cs.tu-berlin.de \
--cc=egcs@egcs.cygnus.com \
--cc=greened@eecs.umich.edu \
/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).