[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Tinycc-devel] question about bit-fields
From: |
Didier Barvaux |
Subject: |
[Tinycc-devel] question about bit-fields |
Date: |
Sun, 27 May 2012 11:12:39 +0200 |
Hello all,
I'm trying to build my project with tcc (yesterday's git version). It
succeeds without any required change (cool!), but tests fail :(
I narrowed the problem to bit-fields, and more especially to the length
of some bit-fields. I created a small test program to explain the
problem:
$ cat test.c
#include <stdint.h>
struct data
{
unsigned int foo:4;
unsigned int bar:4;
uint8_t other;
uint16_t other2;
};
int main(void)
{
return sizeof(struct data);
}
$ gcc -Wall -Werror -Wextra -g -O2 -o test_gcc test.c
$ ./test_gcc ; echo $?
4
$ clang -Wall -Werror -Wextra -g -O2 -o test_clang test.c
$ ./test_clang ; echo $?
4
$ tcc -Wall -Werror -Wextra -g -O2 -o test_tcc test.c
$ ./test_tcc ; echo $?
8
Length 4 is expected, but tcc reports 8. Reporting the expected
length is important because the structure defines a network header.
I then tried to replace unsigned-int-based bitfield by an uint8_t-based
bitfield:
$ cat test2.c
#include <stdint.h>
struct data
{
uint8_t foo:4;
uint8_t bar:4;
uint8_t other;
uint16_t other2;
};
int main(void)
{
return sizeof(struct data);
}
$ gcc -Wall -Werror -Wextra -g -O2 -o test2_gcc test2.c
$ ./test2_gcc ; echo $?
4
$ clang -Wall -Werror -Wextra -g -O2 -o test2_clang test2.c
$ ./test2_clang ; echo $?
4
$ tcc -Wall -Werror -Wextra -g -O2 -o test2_tcc test2.c
$ ./test2_tcc ; echo $?
4
Expected result is given by tcc this time. Problem is that I cannot
change the struct's definition from unsigned int to uint8_t.
Is there an option or a declaration to make tcc compute the expected
length for unsigned-int-based bit fields?
For the record, GCC is version 4.5.3, clang is version 3.0, and tcc is
git rev f98c2306a0857ad3f8800f91e0554a27adc7f675.
Regards,
Didier
signature.asc
Description: PGP signature
- [Tinycc-devel] question about bit-fields,
Didier Barvaux <=