ARM Technical Support Knowledge Articles

FAR VAR _AT_ COMPARED TO CAST VALUE

Applies to: C51 C Compiler

Answer


Information in this article applies to:


SYMPTOM

The 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').

CAUSE

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').

RESOLUTION

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:

#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

Article last edited on: 2007-04-10 12:03:12

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential