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

#INCLUDE directive, variables sharing

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



Joined: 24 Jan 2015
Posts: 63

View user's profile Send private message

#INCLUDE directive, variables sharing
PostPosted: Sun Jan 17, 2021 4:28 am     Reply with quote

I want to figure out how to split my main.c into many files.
For example i have main.c , variables.h and functionA.h .

i use
Code:
#INCLUDE <variables.h>

in main.c , that's ok.

I want to move functionA() from main.c to a new file named functionA.h . However i want functionA.h to be able to read all the variables that main.c uses (and exist in variables.h) AND be able to call other functions from main

i tried including functionA.h into main and is not working. I also tried additional to add
Code:
#INCLUDE <variables.h>
in functionsA.h and remove this declaration from main , that could probably work but i can't call other functions from functionA.h .
With some custom meshing i maybe could fix that but i don't want to get the wrong way.

How can i split my project and all files act like if they were one?
Ttelmah



Joined: 11 Mar 2010
Posts: 19217

View user's profile Send private message

PostPosted: Sun Jan 17, 2021 7:32 am     Reply with quote

Two parts to this:

Order.
Prototypes.

If 'functionA.h', is included after variables.h, then it'll be able to see all these
variables.
However to access functions that are defined in main.h, then these have to be
prototyped _before_ functionA.h is included.

So generate an include file called something like 'mainfunctions.h',
and have this have prototypes for all the main functions.

Then #include the variables.
Followed by the mainfunctions prototype file.
Then the functionsA file.
nuclear__



Joined: 24 Jan 2015
Posts: 63

View user's profile Send private message

PostPosted: Sun Jan 17, 2021 8:20 am     Reply with quote

thank you so much
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