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 CCS Technical Support

Difference to use between .c and .h included files

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



Joined: 08 Mar 2017
Posts: 40

View user's profile Send private message

Difference to use between .c and .h included files
PostPosted: Tue Mar 21, 2017 7:02 am     Reply with quote

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()
{-----;
-----;
----;}
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Tue Mar 21, 2017 1:11 pm     Reply with quote

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.
tssir



Joined: 14 Feb 2016
Posts: 24

View user's profile Send private message

PostPosted: Tue Mar 21, 2017 1:29 pm     Reply with quote

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.
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