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

undefined identifier

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








undefined identifier
PostPosted: Tue Jun 10, 2008 2:40 am     Reply with quote

I have noticed that if I call a function placed after main in the edit window, I get an 'undefined identifier' error at compile time.

If I move the function to before main, it compiles ok.

This seems to be something that has just started happening.

I am also trying to call functions in other .h or .c files but this is not working reliably.

I wonder if I have changed the compiler configuration in some way.

Version 4.071
pic18f8722
Ttelmah
Guest







PostPosted: Tue Jun 10, 2008 3:32 am     Reply with quote

This is totally normal, and expected.
Functions _must_ (and always have had to be) defined, _before_they are used. You can use a 'prototype' definition, so that you can place the actual code latter. So:
Code:

int8 function(int8 val);

void main(void) {
    int8 rval;
    rval=function();
}

int8 function(int8 val) {
    //Actual function code
}


This is normal C.....

Best Wishes
Guest








PostPosted: Tue Jun 10, 2008 3:47 am     Reply with quote

Thanks for the reply.

I know about prototypes, I have them in my code.

If I start a new project then I don't have a problem. With this project I am adding routines to main is now causing a problem.

It is if something has changed in the compiler/project.

I will start a new project and gradually add the files and see what happens.

I started a similar thread a little while trying to add files .h and .c to my project and the problem may be related as I have not resolved this.

Regards,
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Tue Jun 10, 2008 4:01 am     Reply with quote

I have had to do the following:-

I create .h and .c files, prototypes go in .h, code in .c
Each .c file (except the main one) includes its own .h and any other .h it requires.
Each .h has #ifdef to see if it has already been included.

Now this won't actually work until you do the next bit.

In your main file, include the .h for itself but you must include the .c files of any of the others it needs and not their .h files!

This is a pain, but basically this compilers doesn't seem to have a linker. So ALL the code has to be in one main file and the #include (.c) does this for you.

Enjoy
Ttelmah
Guest







PostPosted: Tue Jun 10, 2008 9:30 am     Reply with quote

The compiler has a linker.
It does now work.
You need to flag all functions in the linkable modules, that you want to use, using #EXPORT. In the main, you need to #IMPORT all the modules you want to use.
This is very much the same as in every other linker...

Best Wishes
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