Page 1 of 3

Cross Linking Functions.

PostPosted: Thu Jul 17, 2014 8:33 pm
by SLTom992
I have two C programs in the same project:

The Main which contains all the interrupt procedures and the processes driven by them and the Display which contains all of the graphics display routines and the font.

For the life of me I cannot remember how to make it so that I can call functions across files in the same project. I tried looking it up in two C manuals and couldn't find anything pertinent. I'm using XC-8.

Can someone remind me?

Re: Cross Linking Functions.

PostPosted: Thu Jul 17, 2014 9:44 pm
by vloki

Re: Cross Linking Functions.

PostPosted: Thu Jul 17, 2014 9:47 pm
by ric
That web page wrote:Note:
A newer, revised version of this article has since been posted

Re: Cross Linking Functions.

PostPosted: Thu Jul 17, 2014 10:10 pm
by vloki
ric wrote:
That web page wrote:Note:
A newer, revised version of this article has since been posted

:lol: http://www.microchip.com/forums/FindPost/779164
IanM wrote:@Vloki: I continue to recommend the original because I have taken the time to read it thoroughly and am confident that the C++ content isn't too intrusive...

Re: Cross Linking Functions.

PostPosted: Thu Jul 17, 2014 11:06 pm
by Ian.M
Yep. I've compared them side by side in a two column view and the new version has about 10% extra C++ only stuff and the rest of the text is 10% more verbose but no clearer. The author must have been paid by the word to rehash it!.

Re: Cross Linking Functions.

PostPosted: Fri Jul 18, 2014 3:30 am
by SLTom992
Thanks for the help.

Re: Cross Linking Functions.

PostPosted: Fri Jul 18, 2014 7:06 pm
by SLTom992
OK, obviously I'm missing something obvious - if I use the term "class" as it appears to be used in this explanation I get the error message "unexpected token". If in this document "class" is meant to mean some general term of a more specific term it doesn't appear to be explained in the document plainly.

I should add that although I've been programming in many languages for many years that I suffered a severe concussion that effects the memory strangely (suppose you could still add two plus two but couldn't remember what a "+" sign looked like?)

Re: Cross Linking Functions.

PostPosted: Fri Jul 18, 2014 7:37 pm
by jtemples
"class" is a C++ keyword. You can't use it in C.

Re: Cross Linking Functions.

PostPosted: Fri Jul 18, 2014 8:55 pm
by SLTom992
Then what do you do to link two C files (and .h files) so that they will compile. The error messages I'm getting shows that each C file can't recognize function names or #defines from the other C file.

Re: Cross Linking Functions.

PostPosted: Fri Jul 18, 2014 9:03 pm
by jtemples
#defines are not visible between C files. If you want multiple C files to be able to see them, they have to be in a header file included by those C files. You'll also want to put a declaration of the function prototype in a header file that's included by any C files that want to use the function, as well as by the C file that defines the function.