bit fields in C are a very strange and IMHO ill-faited construct,
I never use them. You don't even have control if the bits are allocated
from the left or from the right in the word; that is not specified in
the standard.
What I do, if I have to deal with bits: use the bit shift operations, and
the logical operations. This is far more portable (of course, the problem
with the endianness remains, but as long as you dont move this data
across system boundaries, all is well ... when moving, you need to convert
this data to a format that will survive the platform move, for example
hexadecimal edited or readable decimal digits).
If you need to be sure about the size of an integer across platforms,
the only way is to define something like
typedef int INT32;
and to do it different on different platforms, controlled by #ifdef ...
but most of the time, this is not needed, because today (for example),
you don't have 16 bit platforms any more, and every int is guaranteed
to have 32 bits.
Kind regards
Bernd
Am 20.11.2014 23:19, schrieb r.m.:
>> -----Original Message-----
>> From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU]
>> Sent: Thursday, November 20, 2014 10:36 AM
>> To: IBM-MAIN@LISTSERV.UA.EDU
>> Subject: Re: How declare in C++ a constant in an assembler module?
> <snip>
>
>> But I'd like to know how, in C, I can specify the size of an integer
>> in bits, so that I get the proper allocation when I am on a 12-bit, an
>> 18-bit, a 24-bit, a 30-bit, a 36-bit, a 48-bit, a 60-bit or a 64-bit
>> machine.
> The standard provides optional types for 8, 16, 32, and 64. In the general
> case, the only way I know is to use a bit-field within a structure. With
> judicious use of placeholder bit-fields, you can even specify which set of
> bits within the bytes you want the integer to occupy.
>
> ----------------------------------------------------------------------
> For IBM-MAIN subscribe / signoff / archive access instructions,
> send email to listserv@listserv.ua.edu with the message: INFO IBM-MAIN
>
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to listserv@listserv.ua.edu with the message: INFO IBM-MAIN
|