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

Automatically load .c file when including .h

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



Joined: 12 Feb 2016
Posts: 11

View user's profile Send private message

Automatically load .c file when including .h
PostPosted: Sat Oct 29, 2016 7:29 pm     Reply with quote

Hi

*edit: forgot to mention I'm using CCS v5.061

I noticed that the include file behaviour is different with CCS when compared to NXP/Freescale CodeWarrier compiler. For example, with CodeWarrier I have main.c with following contents,

Code:

#include <main.h>
#include "types.h"
#include "FIFO.h"
#include "ADC.h"
#include "SCI.h"
#include "packet.h"

void main(void)
{
   // user code here
}


And when I compile, even though each .h files do not have include directive for respective .c file name, it compiles and automatically includes or links the .c files with the same name.

But when with CCS, I have to include both .h and .c files like so,
Code:

#include <main.h>
#include "types.h"
#include "FIFO.h"
#include "FIFO.c"
#include "ADC.h"
#include "ADC.c"
#include "SCI.h"
#include "SCI.c"
#include "packet.h"
#include "packet.c"

void main(void)
{
   // user code here
}


Or, at the end of each header file add include "FIFO.c" etc. Which makes me feel very irritated as my OCD kicks in.

Is there a way for CCS compiler to automatically include the .c files whenever .h files are included?

Thank you
Eric
Ttelmah



Joined: 11 Mar 2010
Posts: 19366

View user's profile Send private message

PostPosted: Sun Oct 30, 2016 12:32 am     Reply with quote

Just have your .h files include their .c's.

Actually, it is probably not 'including' the .c files. My guess is that these have already been pre-compiled, so it is just _linking_ them. This would be the standard behaviour for a normal linking compiler, but does mean that the files have been compiled already.

Have a look at:
<http://stackoverflow.com/questions/10068002/when-including-a-header-file-in-c-does-it-automatically-include-the-c-file-of>
shson



Joined: 12 Feb 2016
Posts: 11

View user's profile Send private message

PostPosted: Sun Oct 30, 2016 4:11 am     Reply with quote

Ah yes, you're right. After reading the you provided at stackoverflow.com and digging through the CodeWarrier manual, it just "links" the files and the compiler automatically compiles all relevant .c files. Like you suggested, I put .h include directive at the top of .c files and have main.c include the .c files, not .h files. It worked.

Cheers
Eric
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