This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
option -funsigned-bitfields bug
- From: darwin <yuanyj at neusoft dot com>
- To: bug-gcc at gnu dot org
- Date: Sat, 16 Nov 2002 07:52:52 +0800
- Subject: option -funsigned-bitfields bug
- Organization: neusoft
Hi GCC guys,
I think I found a bug with option -funsigned-bitfield.
I wrote an example like this:
$ cat example.cxx
#include <stdio.h>
class selector_class
{
unsigned short _rpl:2;
unsigned short _ti:1;
unsigned short _index:13;
}__attribute__((aligned(2)));
int main(int __argc, char* __argv[])
{
printf("sizeof(a) = (%d)\n", sizeof(selector_class));
return 0;
}
$ gcc -funsigned-char -funsigned-bitfields example.cxx
$ ./a.out
sizeof(a) = (2)
Everything went right.
But if I wrote it like this:
$ cat example.cxx
#include <stdio.h>
typedef unsigned short uint16_t;
class selector_class
{
uint16_t _rpl:2;
uint16_t _ti:1;
uint16_t _index:13;
}__attribute__((aligned(2)));
int main(int __argc, char* __argv[])
{
printf("sizeof(a) = (%d)\n", sizeof(selector_class));
return 0;
}
$ gcc -funsigned-char -funsigned-bitfields example.cxx
$ ./a.out
sizeof(a) = (4)
It's obvious that the result is not correct. I'm not sure if I missed
something. If you don't think it's a bug, let me know the reason, please.
Thanks in advance.
Best Regards, darwin