View previous topic :: View next topic |
Author |
Message |
shson
Joined: 12 Feb 2016 Posts: 11
|
Automatically load .c file when including .h |
Posted: Sat Oct 29, 2016 7:29 pm |
|
|
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: 19552
|
|
Posted: Sun Oct 30, 2016 12:32 am |
|
|
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
|
|
Posted: Sun Oct 30, 2016 4:11 am |
|
|
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 |
|
|
|