public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Quieten -Wconversion warnings for bit-fields
@ 2008-03-03 11:35 Christian Iseli
  2008-03-23 19:16 ` Manuel López-Ibáñez
  0 siblings, 1 reply; 3+ messages in thread
From: Christian Iseli @ 2008-03-03 11:35 UTC (permalink / raw)
  To: gcc-help

Dear all,

Given:
---- test.c ----
typedef struct _my_struct_t {
  unsigned int small:1;
  unsigned int big:31;
} my_struct_t, *my_struct_p_t;

void
my_func(unsigned int sm, unsigned int bi, my_struct_p_t msp)
{
  msp->small = sm;
  msp->big = bi;
}
----

and:
gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-cpu=generic --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.3.0 20080229 (Red Hat 4.3.0-0.13) (GCC)

and:
gcc -O2 -std=gnu99 -W -Wall -Wconversion -pedantic -c test.c

I get:
test.c: In function ‘my_func’:
test.c:9: warning: conversion to ‘unsigned char:1’ from ‘unsigned int’ may alter its value
test.c:10: warning: conversion to ‘unsigned int:31’ from ‘unsigned int’ may alter its value

I can't seem to find a typecast incantation that would tell GCC that I
did indeed take proper precautions and that the assignment is fine.

I also tried "msp->small = sm & 1U;" but it doesn't help

Any hints ?

Thanks,
					Christian

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

end of thread, other threads:[~2008-03-25 23:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-03 11:35 Quieten -Wconversion warnings for bit-fields Christian Iseli
2008-03-23 19:16 ` Manuel López-Ibáñez
2008-03-25 23:30   ` Christian Iseli

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).