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

Can a "#define DATA RB0" be confused with a variab

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



Joined: 17 Oct 2005
Posts: 98

View user's profile Send private message

Can a "#define DATA RB0" be confused with a variab
PostPosted: Wed Jul 19, 2006 6:06 am     Reply with quote

Hello forum,

As the subject says, can a

Code:
#define DATA RB0


be confused with a variable name?

Eg. I have defined RB0 to be accessed by typing DATA in my code.
Next, I have a function that takes an argument like

Code:
void functionname(int8 data)
{
}


Can those 2 names be mixed up in the compiler? I don't receive any warnings with version 3.249, but I think a problem was solved when I changed one of the names.


Thanks.

Edit: Actually, it is only when I use both of the names in the same function that the problem occur:

Code:
#define DATA RB0

int8 functionname(int8 data)
{
   DATA = 1; // Set RB0 high
   data = 10; // Set variable to 10
   return data;
}


Somehow the above code will compile, but it won't work right in the PIC.
Ttelmah
Guest







PostPosted: Wed Jul 19, 2006 6:34 am     Reply with quote

Yes, of course it can.
The #define, is a _macro_ definition. It is used before the actual compiler pass. So in the example given, the function definition will become:
Code:

void functionname(int8 rb0)
{
}

Now if you want to use case to distinguish between such things, then add the #case directive to the code, to enable case sensitivity.
There is no 'confusion', since the expansion happens _before_compilation. The only confusion will come if 'rb0', itself has a meaning, which will then result in the function changing something it shouldn't.

Best Wishes
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

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

PostPosted: Wed Jul 19, 2006 6:54 am     Reply with quote

Not exactly the same problem as RJ outlined but I've chased a few bugs from other peoples code that would have been settled had the #case directive been used at the start of the file.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Futterama



Joined: 17 Oct 2005
Posts: 98

View user's profile Send private message

PostPosted: Wed Jul 19, 2006 7:10 am     Reply with quote

Thanks, I didn't realize there was a #case directive.
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