|
|
View previous topic :: View next topic |
Author |
Message |
Neddie Guest
|
Basic 'C' question |
Posted: Thu Oct 01, 2009 4:38 am |
|
|
Hi to all.
CCS is the only compiler that I have come across where one has to include
".c" files.
Is it not normal practice to include only header (".h") files, that contain the
function prototypes for the functions you wish to call in different files.
I've tried doing this and the compiler can't find the functions.
Am I missing something obvious?
Cheers
Rob |
|
|
Ttelmah Guest
|
|
Posted: Thu Oct 01, 2009 7:38 am |
|
|
Just including the definition headers, would not be 'enough', on just about any compiler. You would also have to include the actual run time code, into the final 'link' stage. Many though do this 'under the hood', automatically having standard libraries that are searched.
The key though, is to understand that most 'compilers', are under the skin, compilers, and linkers. It is the linker, that resolves the undefined code. Historically many older compilers did not have this 'luxury', which has both advantages and disadvantages. Advantage is primarily that standard subroutines don't have to be compiled each time, and can be distributed, without distributing the source code. Downside, is that this 'precompiled' code, cannot be optimised for the final application, where savings may exist in a particular job.
Historically, the CCS compiler, was purely a compiler, not compiler/linker. V4, potentially added linking, and it does now work to a large extent, but you would still have to precompile the 'library' you want to use, add the instructions to tell the compiler that the definitions of these functions are 'external', and link the library after compiling the main code.
Best Wishes |
|
|
mbradley
Joined: 11 Jul 2009 Posts: 118 Location: California, USA
|
|
Posted: Thu Oct 01, 2009 10:41 pm |
|
|
Just to touch on the above explanation...
If you have a .c file with a function that has never been compiled and you only include a .h file with the prototypes, then any compiler would not compile correctly.
More directly, if this is C code specifically for this application and not a C function from a library, then even more so does it makes sense to include the .c file with any compiler.
To reiterate, if I am writing a C application in Linux, and I decide to write a function and store it in a C file, it will have to be included, because it was never compiled into a library or stored in any scanned directory.
ok, if I babble anymore I will just start confusing everything. |
|
|
Neddie Guest
|
|
Posted: Mon Oct 05, 2009 12:36 am |
|
|
Thanks guys for clearing things up for me.
Interesting stuff!!
Cheers
Rob |
|
|
|
|
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
|