View previous topic :: View next topic |
Author |
Message |
zaskzask
Joined: 27 Jun 2017 Posts: 3
|
include header files in my project to include the .c |
Posted: Tue Jun 27, 2017 12:20 pm |
|
|
Hi ,
I can't seem to understand how to do a ccs project.
In my main.c I include the header files (which include the prototypes of the functions defined in the .c file) :
Code: |
#include<x.h>
#include<y.h>
#include<z.h> |
but when I compile, this doesn't seem to include automatically the
x.c
y.c
z.c
files. How to do this? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Tue Jun 27, 2017 1:51 pm |
|
|
It won't.
Including the .h file never includes the .c.
What is misleading you is that if you are using a compiler that supports pre-compiled libraries, then when you include the .h, the compiler will search the libraries, and if then code is already compiled and there, this code will be loaded at the link stage after compilation. It doesn't include the .c file though.
CCS by default is not a library based compiler.
You can pre-compile the C code, and then include it, but you have to do this yourself. However CCS is optimised on the basis of being able to compile as much as possible at the same time to help optimisation. You have to include the actual code yourself. |
|
![](templates/subSilver/images/spacer.gif) |
zaskzask
Joined: 27 Jun 2017 Posts: 3
|
|
Posted: Tue Jun 27, 2017 2:47 pm |
|
|
Does this mean that people usually write all the code in just one .c file?
The correct way for putting together my code would be to include the .c in the main?
Code: |
#include<x.c>
#include<y.c>
#include<z.c>
//main()
//...
|
So what is the purpose of the .h? |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Tue Jun 27, 2017 5:12 pm |
|
|
For me *.h files should be 'header' files that pass information to either the main program or to 'drivers' files.
I am NOT a died in the wool , officially school taught C programmer and frankly there's all sorts of 'implementations' to C anyway,so there is no ONE S to use.
The best example of a .h file is the PICtype.h at the beginning of every program. It contains information to tell the compiler what PIC you're using, so to me .h seems OK.
Drivers on the other hand, say for LCD modules, I2C chips, etc. I'd prefer to have filename.dvr to denote it is a DRIVER, contains code specifically to control a device or internal peripheral, but for some reason .C is the 'standard'.
I like filename.c to be the 'main()' or real program, in essence the 'guts' of the code.
I'm sure there are 100+ ways to look at it, none are right, none are wrong. What is important is to name the files in a way that says WHAT they are for or do.It makes debugging a lot easier 3 days from now....
Jay |
|
![](templates/subSilver/images/spacer.gif) |
jeremiah
Joined: 20 Jul 2010 Posts: 1328
|
|
Posted: Tue Jun 27, 2017 7:50 pm |
|
|
zaskzask wrote: | Does this mean that people usually write all the code in just one .c file?
The correct way for putting together my code would be to include the .c in the main?
Code: |
#include<x.c>
#include<y.c>
#include<z.c>
//main()
//...
|
So what is the purpose of the .h? |
we use multiple C files. we just
#include "something.c" at the bottom of the main file. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Wed Jun 28, 2017 12:23 am |
|
|
Or, something.c, in the .h file.
Look for example at ex_usb_to_serial.c
Has the main code.
This #includes 'ex_usb_common.h', which does the processor setups, then #includes 'usb_cdc.h'. This has the prototypes data definitions etc., needed, but then #includes 'usb.c', which is the actual usb driver code. |
|
![](templates/subSilver/images/spacer.gif) |
|