This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Widening bitfields for arguments


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]