Mail Archives: djgpp/1999/11/16/13:39:50
In article <3830CB40 DOT 79BAB916 AT home DOT com> you wrote:
> I saw somewhere that u could assign variables to certain bits in a
> variable. something like:
> stuct INFO {
> 0 : Active;
> 1,2 : Mode;
> } Info;
This is by no means a DJGPP-specific question, i.e. it should have
been asked in the general C newsgroup(s), not here. Anyway, I'll make
an attempt to end it quickly:
* Yes, such a feature does exist in C.
* No, the example above is not the correct syntax of it.
* The name of this feature is 'bitfields'
* You want to get a good text book on C (Kernighan and Ritchie, 2nd ed.,
e.g.) that covers this.
* You can generally *not* safely use it to access single bits in
an externally predefined dataformat (like hardware bits, or stuff),
if your program is supposed to be anywhere near portable among
different compilers, let alone operating systems or hardware platforms.
In short: usability of bitfields is rather limited, to the point that
I don't recall ever having seen them in use in any of the C program
sources I've looked into. In *years* of looking, that is.
> This would be better than what I am currently doing, which is bitwise
> math to get the info that i want.
Due to the above shortcomings, everyone seems to stick to explicit
bit-fiddling, anyway. Better get used to it.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -