C51: Far Var _at_ Compared to Cast Value
Information in this article applies to:
The following function:
always returns a zero ('0') even though it should return one ('1').
Addresses 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').
The 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:
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:
Last Reviewed: Thursday, February 25, 2021
of your data.