www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/15/12:16:48

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Individual Bits
Date: Wed, 15 Apr 1998 08:46:21 -0700
Organization: Alcyone Systems
Lines: 41
Message-ID: <3534D64D.124C939A@alcyone.com>
References: <35343EFB DOT FA2644E7 AT gold DOT com DOT br>
NNTP-Posting-Host: charmaine.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Sérgio Vale e Pace wrote:

>     I'm trying to make a struct to work something like this:
> 
> defined_struct data;
> data=8;
> data.bit0=1; // data=9
> data.bit2=1; //data=13
> 
> or at least
> 
> defined_struct data;
> data.value=8;
> data.bit0=1; // data=9
> data.bit2=1; //data=13
> 
> but I'm not figuring how can somebody give-me some help.

Use bitfields:

    struct S {
        unsigned bit0 : 1;
        unsigned bit1 : 1;
        unsigned bit2 : 1;
        unsigned bit3 : 1;
        unsigned bit4 : 1;
            ...
    };

-- 
         Erik Max Francis, &tSftDotIotE / mailto:max AT alcyone DOT com
                       Alcyone Systems / http://www.alcyone.com/max/
  San Jose, California, United States / icbm:+37.20.07/-121.53.38
                                     \
 "All the people in my neighborhood / look and get mad and sing"
                                   / Public Enemy

- Raw text -


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