cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1999/11/16/13:39:50

Date: Tue, 16 Nov 1999 14:17:30 +0100
From: Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de>
Message-Id: <199911161317.OAA24962@acp3bf.physik.rwth-aachen.de>
To: robbat2 AT home DOT com (Robin Johnson)
Cc: djgpp AT delorie DOT com
Subject: Re: Bit mapped fields?
Newsgroups: comp.os.msdos.djgpp
Organization: RWTH Aachen, III. physikalisches Institut B
X-Newsreader: TIN [version 1.2 PL2]
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019