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 support@ccsinfo.com

Function prototypes and multiple file programs

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



Joined: 08 Sep 2004
Posts: 5
Location: Ipswich

View user's profile Send private message

Function prototypes and multiple file programs
PostPosted: Wed Sep 08, 2004 10:04 am     Reply with quote

I have just loaded the CCS compiler, I have been using the Keil compiler for 8051.

IN the Keil compiler you create the initial program file with the main() function and include .h containing the function prototypes for functions located in other files. This does not appear to work. Secondly, when the compiler starts to compile the second file it complains that there is no main() function in it.

I am sure that it is something which is easily solved but I have not managed to find anything to tell me what I am doing wrong.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Sep 08, 2004 10:17 am     Reply with quote

There is only one "C" file to be compiled. Other "C" files would have to be included in the main C file.
StuH_CC



Joined: 07 May 2004
Posts: 16
Location: Shropshire, UK

View user's profile Send private message

PostPosted: Wed Sep 08, 2004 10:22 am     Reply with quote

The CCS compiler only supports one program (.c) source file. The concept of projects, with associated makefiles, is foreign to CCS C.

The usual workaround is to #include all the .c files in a project, e.g. in your main source it would look something like:
Code:

#include <16F876a.h>
#include "prototypes.h"

#fuses HS,WDT,NOPROTECT,BROWNOUT,PUT,NOLVP     //example!

//more setup here

#include "file_one.c"
#include "file_two.c"

void main( void )
{
       //code here
}

It may not even be necessary to have any prototypes, depending on whether the function in question is called before or after its definition.

Stu.
JBM



Joined: 12 May 2004
Posts: 54
Location: edinburgh, Scotland

View user's profile Send private message

Includiong .c
PostPosted: Wed Sep 08, 2004 10:24 am     Reply with quote

In the .h file you refrence from the main file, do you also #include the .c file for those functions after the prototypes? eg

Code:

------
<file main.c>
------

#include *.h

...

main()
{

}

------
file *.h
------

void function1();
void function2();
...


#include "*.c"
-----


This means you only compile the main.c file and the compiler refrences the other source files for you.

( or you could just add the code for the functions to the .h file after the prototypes, although it is a little unconventional )
Wraith



Joined: 08 Sep 2004
Posts: 5
Location: Ipswich

View user's profile Send private message

Further information
PostPosted: Wed Sep 08, 2004 10:34 am     Reply with quote

I am using the CCS compiler through MPLABS.

I have just had a further thought. In the Keil software the files are compiled and then linked. Does this software just expect to compile one file (no linking required)? I have sucessfully compiled my skeleton structure using the line:

#include "adc control.c"

to include the file and removed 'adc control.c' from the source files section of the project (just leaving 'main.c').

Is this the way that the compiler has to be used through MPLABS?
Wraith



Joined: 08 Sep 2004
Posts: 5
Location: Ipswich

View user's profile Send private message

PostPosted: Wed Sep 08, 2004 10:53 am     Reply with quote

Thanks for the help. This seems a bit alien to me but I am sure that I will get used to it, must have been using the keil compiler to long (7 years).
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Sep 08, 2004 11:02 am     Reply with quote

Nope, its Alien! Very Happy
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