![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
jpts
Joined: 08 Mar 2017 Posts: 40
|
Difference to use between .c and .h included files |
Posted: Tue Mar 21, 2017 7:02 am |
|
|
What the best way to declareted variables using .c or .h
Compile both works with no problem...
Ex: Code: |
#include <main.h>
#include <variables.h> or #include <variables.h> what suggest ?
void main()
{-----;
-----;
----;} |
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19382
|
|
Posted: Tue Mar 21, 2017 1:11 pm |
|
|
This is a history/taste/setup thing.
Generally the standard is that ones that actually contain 'code' should be .c. and those only containing declarations, definitions, & function prototypes use .h.
Ideally (properly configured), you set the .h file up so it will only set things up once (so tests if a constant is #defined, and does nothing if it already is). Now with most C's, that use libraries, you only need to include the .h file, and then the .c file is not included, because it has been pre-compiled, and it's code is then loaded as a library. Though you can do this, with CCS it is more efficient to instead then include the .c file, and include it in the compilation. |
|
![](templates/subSilver/images/spacer.gif) |
tssir
Joined: 14 Feb 2016 Posts: 24
|
|
Posted: Tue Mar 21, 2017 1:29 pm |
|
|
C file is for "to compile" code. H (header) file for declarations (structure, class, function prototype, macro, ...).
With "normal" compiler, each .c files become an .o (object). Then you must execute linking procedure over all the .o files to make an executable file. H files should contain some symbols and interfaces, with no code to compile. But with template and other stuffs, it is not an evidence.
Ccsc have compiling and linking procedure in same command.
Then you can mix .c and .h files with same result. As you wish ...
With CCS, i usualy set library, drivers, peripheral code, and some generic shared code as .h file. Only the main code is .c file. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|