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

include header files in my project to include the .c

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



Joined: 27 Jun 2017
Posts: 3

View user's profile Send private message

include header files in my project to include the .c
PostPosted: Tue Jun 27, 2017 12:20 pm     Reply with quote

Hi Smile ,

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?
Ttelmah



Joined: 11 Mar 2010
Posts: 19544

View user's profile Send private message

PostPosted: Tue Jun 27, 2017 1:51 pm     Reply with quote

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



Joined: 27 Jun 2017
Posts: 3

View user's profile Send private message

PostPosted: Tue Jun 27, 2017 2:47 pm     Reply with quote

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?
temtronic



Joined: 01 Jul 2010
Posts: 9244
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jun 27, 2017 5:12 pm     Reply with quote

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
jeremiah



Joined: 20 Jul 2010
Posts: 1355

View user's profile Send private message

PostPosted: Tue Jun 27, 2017 7:50 pm     Reply with quote

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



Joined: 11 Mar 2010
Posts: 19544

View user's profile Send private message

PostPosted: Wed Jun 28, 2017 12:23 am     Reply with quote

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