CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

how to test for bits in a structure

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
MikeW



Joined: 15 Sep 2003
Posts: 184
Location: Warrington UK

View user's profile Send private message

how to test for bits in a structure
PostPosted: Thu Sep 06, 2007 2:23 am     Reply with quote

I am trying to test bits in a structure, can anyone help ?


this fails with " element is not a member".

how do I do a bit test to get a true/false ?

code --------------------


if (!current_data.Sequential_Shutter_Active_flag) // not active
{
// do something 'cos the bit is 0 not 1
}


structure definition ------------

struct data
{
long magicnumber;
signed level;
signed gain;
signed long ref_os;
int ext_ref_freq;
int address;
signed ref_state;
short NTSC_60Hz_flag;
short Sequential_Shutter_Active_flag;
short rs485;
short extref;
short rs422;
short rs232;
short ref_int;
short ref_ext;
short ref_auto;
short dummy1; //not used for anything, allows us to have an even amount of memory.
short dummy2; //not used for anything, allows us to have an even amount of memory.
short dummy3; //not used for anything, allows us to have an even amount of memory.
short dummy4; //not used for anything, allows us to have an even amount of memory.
short dummy5; //not used for anything, allows us to have an even amount of memory.
short dummy6; //not used for anything, allows us to have an even amount of memory.
short dummy7; //not used for anything, allows us to have an even amount of memory.
int chksum; //data checksum - equal to everything in the struct except this number
// mod 255.
};

struct data current_data;
libor



Joined: 14 Dec 2004
Posts: 288
Location: Hungary

View user's profile Send private message

PostPosted: Thu Sep 06, 2007 2:42 am     Reply with quote

you can only use this syntax for bit fields: (There is an issue with byte boundaries, I think, you can't cross a byte with a bit field. Using 1 bit fields this does not concerns your code.)
Code:
struct data_record {
int a;
int b : 2; //2 bits
int c : 3; //3 bits
int d : 1; //1 bits
int d;
}data_var;
MikeW



Joined: 15 Sep 2003
Posts: 184
Location: Warrington UK

View user's profile Send private message

PostPosted: Thu Sep 06, 2007 2:57 am     Reply with quote

libor, sorry you are wrong.


the error is caused by the naming

reducing current_data.Sequential_Shutter_Active_flag to
current_data.Seq_Shutter_Active_flag



if (current_data.Seq_Shutter_Active_flag==OFF) // not active


it now compiles Very Happy
libor



Joined: 14 Dec 2004
Posts: 288
Location: Hungary

View user's profile Send private message

PostPosted: Thu Sep 06, 2007 3:08 am     Reply with quote

OK. thanks for the info, so you just reached the variable name length limit. ..and I have been avoiding using shorts in structs in vain. Shocked
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group