The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 04-23-2002
amatsaka amatsaka is offline
Registered User
 

Join Date: Mar 2002
Location: Greece
Posts: 14
Bit-fields and Bitwise operators

Hi,
Is it possible to use bitwise operators in bit fields?
For example:

typedef struct Mystruct {
unsigned char A :1 ;
unsigned char B :1 ;
} Mystruct;

and assume

struct Mystruct STR_1S, STR_2S, tempSTRS = {0};

then the following line:

tempSTRS = STR_1S & STR_2S;
gives the error:

operants must have integral type: op "&"

One way to overcome the problem is to perform the bitwise operations in each member separelty i.e.
tempSTRS.A = STR_1S.A & STR_2S.A;
tempSTRS.B = STR_1S.B & STR_2S.B;

Is there any other more eficient way?
Reply With Quote
Remove advertisements
!!
Forum Sponsor