C
Chris McDonald
Section 6.7.2.1(4) of the C Standard TC1 states that the type of a
bit-field (in structures) may only be a _Bool, signed int, unsigned int,
or an implementation-defined type.
I'm trying to compile some code requiring a 16-bit integer to have a
number of bit fields. I prefer to develop standards-conforming code as
much as possible, so I'm compiling with
<OT>
gcc -std=c99 -pedantic -Wall -o try try.c
With the -pedantic switch, the appended code raises a warning for Control2
because of version's type. Without -pedantic no warning is raised.
</OT>
I believe that I understand this all (please correct me if I'm wrong),
but am wondering:
- As the size of the standard types specified in Section 6.7.2.1(4) of TC1
are all architecture-dependent, why does the standard limit bit-fields
to this list of types?
- Is/has there been any discussion about permitting the integer types in
<stdint.h> to be used as bit-fields, e.g. int16_t version:2 ;
- Is it possible to write standards-conforming code when a known,
fixed-size object with bit-fields is required?
Thanks,
______________________________________________________________________________
Dr Chris McDonald E: (e-mail address removed)
Computer Science & Software Engineering W: http://www.csse.uwa.edu.au/~chris
The University of Western Australia, M002 T: +618 6488 2533
Crawley, Western Australia, 6009 F: +618 6488 1089
#include <stdio.h>
#include <stdint.h>
typedef struct {
int version :2;
} Control1;
typedef struct {
unsigned short version :2;
} Control2;
int main(int argc, char *argv[])
{
return(0);
}
bit-field (in structures) may only be a _Bool, signed int, unsigned int,
or an implementation-defined type.
I'm trying to compile some code requiring a 16-bit integer to have a
number of bit fields. I prefer to develop standards-conforming code as
much as possible, so I'm compiling with
<OT>
gcc -std=c99 -pedantic -Wall -o try try.c
With the -pedantic switch, the appended code raises a warning for Control2
because of version's type. Without -pedantic no warning is raised.
</OT>
I believe that I understand this all (please correct me if I'm wrong),
but am wondering:
- As the size of the standard types specified in Section 6.7.2.1(4) of TC1
are all architecture-dependent, why does the standard limit bit-fields
to this list of types?
- Is/has there been any discussion about permitting the integer types in
<stdint.h> to be used as bit-fields, e.g. int16_t version:2 ;
- Is it possible to write standards-conforming code when a known,
fixed-size object with bit-fields is required?
Thanks,
______________________________________________________________________________
Dr Chris McDonald E: (e-mail address removed)
Computer Science & Software Engineering W: http://www.csse.uwa.edu.au/~chris
The University of Western Australia, M002 T: +618 6488 2533
Crawley, Western Australia, 6009 F: +618 6488 1089
#include <stdio.h>
#include <stdint.h>
typedef struct {
int version :2;
} Control1;
typedef struct {
unsigned short version :2;
} Control2;
int main(int argc, char *argv[])
{
return(0);
}