| ||||||||
Technical Support Support Resources Product Information | C51: FAR VAR _AT_ COMPARED TO CAST VALUEInformation in this article applies to:
SYMPTOMThe following function:
char far far_var[10] _at_ 0x021234;
char test (void)
{
char far *fp1 = far_var;
char far *fp2 = (void far *) 0x021234L;
if (fp1 == fp2)
return(1);
else
return(0);
}
always returns a zero ('0') even though it should return one ('1'). CAUSEAddresses specified with the _at_ are converted into a memory type byte + offset combination. So, the variable located using _at_ 0x021234 has an address of 0x031234. Values cast into an address are assumed to have the correct memory type byte + offset combination. So, the type cast (void far *) 0x021234L has an address of 0x021234. Based on these conversion rules, these two addresses are not identical. And, the function returns a zero ('0'). RESOLUTIONThe best way to resolve this issue is to use the FVAR macro from ABSACC.H in place of the type cast: &FVAR(char,0x021234). For example:
#include <absacc.h>
char far far_var[10] _at_ 0x011234;
char test (void)
{
char far *fp1 = far_var;
char far *fp2 = &FVAR(char,0x021234L);
if (fp1 == fp2)
return(1);
else
return(0);
}
Another way to resolve this issue is to change either the _at_ address to 0x011234 or change the type cast to 0x031234. But don't change both. For example:
char far far_var[10] _at_ 0x011234;
char test (void)
{
char far *fp1 = far_var;
char far *fp2 = (void far *) 0x021234L;
if (fp1 == fp2)
return(1);
else
return(0);
}
MORE INFORMATION
SEE ALSO
Last Reviewed: Tuesday, April 10, 2007 | |||||||
| ||||||||