View previous topic :: View next topic |
Author |
Message |
Futterama
Joined: 17 Oct 2005 Posts: 98
|
Can a "#define DATA RB0" be confused with a variab |
Posted: Wed Jul 19, 2006 6:06 am |
|
|
Hello forum,
As the subject says, can a
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
|
|
Posted: Wed Jul 19, 2006 6:34 am |
|
|
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
|
|
Posted: Wed Jul 19, 2006 6:54 am |
|
|
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
|
|
Posted: Wed Jul 19, 2006 7:10 am |
|
|
Thanks, I didn't realize there was a #case directive. |
|
|
|