View previous topic :: View next topic |
Author |
Message |
nuclear__
Joined: 24 Jan 2015 Posts: 63
|
#INCLUDE directive, variables sharing |
Posted: Sun Jan 17, 2021 4:28 am |
|
|
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: 19552
|
|
Posted: Sun Jan 17, 2021 7:32 am |
|
|
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
|
|
Posted: Sun Jan 17, 2021 8:20 am |
|
|
thank you so much |
|
|
|