473,395 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

creating bit packed Global structures in C

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
3 1231
weaknessforcats
9,208 Expert Mod 8TB
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
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
9,208 Expert Mod 8TB
Yes, I've used that one myself.
Jul 8 '16 #4

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

Similar topics

0
by: MiLoS | last post by:
I need to have a com object accessible throughout the website mon a windows machine using PHP and Apache. I am able to use the COM object in my php scripts but the object gets re-instantiated for...
1
by: Ori Y | last post by:
Hi , i'm having some difficulties regarding using the Python/c api. I'm trying to bulid a deeply nested datastructure (i.e dict within a dict or list within a dict) Building the data stracture...
7
by: Carlos | last post by:
Ok, I am a VB developer but need to do a C# program, my question is how do I decalre a global variable in c#, in VB.net I juest create a procedure an declare my Variable as Public myVar and I can...
4
by: Harry | last post by:
Good Day, I am writing a code for the H.264 Video codec.I am using VC++ compiler,but programming is in c only.I have grouped the related global variables under one structure in a header file...
11
by: jj555s | last post by:
I've been trying use use a Global Struct however I get this eeror message: error C2236: unexpected 'struct' 'my_struct' my code (MyStruct.h) struct my_struct { int box2; } extern struct...
3
by: zybonje | last post by:
how can i make a global variable that can be used in all forms of my projects
5
by: tech.rawsteak | last post by:
I have a function that retrieves a user's login name from their workstation and looks it up on an employee table to return their full name (ie: jsmith -John Smith). Their full name is then...
2
by: xxsodapopxx5 | last post by:
Hi everyone, I am new to C# and am having problems creating arrays like i did in VB.net. Right now i have a structure lets say called stuBox and it has a few items in it struct stuBox ...
8
by: rottmanj | last post by:
. In order to teach my self more. I have started to convert some of my cf scheduled tasks to perl applications. One area where things are kind of fuzzy is setting up global variables that can be...
2
by: Jim in Arizona | last post by:
I'm making an app that inputs into multiple tables. I'm using the SCOPE_IDENTITY() SQL function for foreign key purposes. I input into the main table first and retrieve the scope_identity() and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.