* Widening bitfields for arguments
@ 2001-04-25 9:09 Jakub Jelinek
2001-04-25 10:00 ` Joseph S. Myers
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2001-04-25 9:09 UTC (permalink / raw)
To: Joseph S. Myers; +Cc: gcc
Hi!
struct foo
{
unsigned int a:16;
};
void bar (unsigned int);
struct foo x;
void baz (void)
{
bar (x.a);
}
gives a warning with -Wconversion unless -traditional:
passing arg 1 of `bar' as unsigned due to prototype
, but when I tried it on i386 and sparc64 without the
bar prototype, the value was passed zero extended, not
sign extended (unless a's type was changed to int). The
-Wconversion warning is emitted even for:
struct foo
{
unsigned int a:16;
};
void bar (unsigned int);
struct foo x;
void baz (void)
{
bar ((unsigned int)x.a);
}
where it definitely looks like a bug.
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Widening bitfields for arguments
2001-04-25 9:09 Widening bitfields for arguments Jakub Jelinek
@ 2001-04-25 10:00 ` Joseph S. Myers
0 siblings, 0 replies; 2+ messages in thread
From: Joseph S. Myers @ 2001-04-25 10:00 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc
On Wed, 25 Apr 2001, Jakub Jelinek wrote:
> Hi!
Please submit these issues as PRs.
> struct foo
> {
> unsigned int a:16;
> };
>
> void bar (unsigned int);
>
> struct foo x;
>
> void baz (void)
> {
> bar (x.a);
> }
>
> gives a warning with -Wconversion unless -traditional:
> passing arg 1 of `bar' as unsigned due to prototype
> , but when I tried it on i386 and sparc64 without the
> bar prototype, the value was passed zero extended, not
> sign extended (unless a's type was changed to int). The
Yes. The integer promotions preserve value. int can represent all values
of the bitfield, so the default promotion makes it int. It's simply that
the warning is useless in this case and -Wconversion is meant to avoid
warning in such a case.
--
Joseph S. Myers
jsm28@cam.ac.uk
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2001-04-25 10:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-25 9:09 Widening bitfields for arguments Jakub Jelinek
2001-04-25 10:00 ` Joseph S. Myers
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).