By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,950 Members | 1,032 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,950 IT Pros & Developers. It's quick & easy.

creating bit packed Global structures in C

P: 2
In my Main.c file I declare a structure:

typedef struct FlagStructure{
unsigned int RxActive:1;
unsigned int TxActive:1;
}FlagStructure;

FlagStructure SerialFLAG = {0,0};

I can then set a bit SerialFLAG.RxActive =1

I want to be able read/write this bit from other programs, I want a global structure


In a file "Serial.C" I already declare global variables:

extern volatile unsigned int RxRdPtr;

They work fine BUT when I try

extern FlagStructure SerialFLAG;

I get

Serial.c:30:33: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'SerialFLAG'
Serial.c: In function 'SerialRxByte':
Serial.c:47:9: error: 'SerialFLAG' undeclared (first use in this function)

Do I need to declare the struct in a header file ? Is there a better way of bit packing flags ?

Thanks for your help

Dren
Jul 7 '16 #1
Share this Question
Share on Google+
3 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
In serial.c you use the term FlagStructure but the compiler has never heard of that term so you get an error.

You have to include your typedef in serial.c.

Here's where I would put the struct typedef in a header and #include the header in all your .c files.

Remember, files are compiled separately. No info carries from one file to the next so you need to include all info used in the file so it compiles by itself.
Jul 7 '16 #2

P: 2
Of course now you point it out, arrgh, obvious !

I can only suggest that I have a bad cold and therefore a bit dim at the moment.

Thanks for your help. You star !
Jul 8 '16 #3

weaknessforcats
Expert Mod 5K+
P: 9,197
Yes, I've used that one myself.
Jul 8 '16 #4

Post your reply

Sign in to post your reply or Sign up for a free account.