This is the mail archive of the gcc-bugs@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]
Other format: [Raw text]

option -funsigned-bitfields bug


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


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