Home > Back-end >  Symbol "@" in C language
Symbol "@" in C language

Time:09-06

I would like to ask you about assign specific memory adress for variable in C language. I need to setup Understand SciTool software, and I have some issues about it.

Please have a look:

    #define dPU1      0xF0031
      __SFR_EXTERN__ __near __no_init volatile union
      {
      TByte         ioPU1;
      TBitfieldByte ioPU1_Bits;
      } @dPU1;

dPU1 is a register adress (Renesas RL78). Understand SciTool cant process it. I recived those messages:

[E] pasting formed '@dSMR02', an invalid preprocessing token;

[E] expected ';' after union

[E] expected identifier or '('

I can't find any information about "@" in C language. Any idea? Thanks!

CodePudding user response:

Many compilers for embedded control accept certain extensions to place objects at absolute addresses.

Apparently your compiler allows to specify it via this notation.

In contrast, code analyzers are generic tools. They rarely know such extensions and so you receive this error message.

This is a good reason to wrap such an extension in a macro. This macro will be differently defined depending on the tool that parses the source. If your compiler reads the source, it provides the absolute address. If the analyzer reads the source, it expands to nothing.

This suggestion is untested:

#if defined(/* some macro that is automatically set by your compiler */)
#define AT(x) @x
#else
#define AT(x)
#endif

#define dPU1      0xF0031

__SFR_EXTERN__ __near __no_init volatile union
{
    TByte         ioPU1;
    TBitfieldByte ioPU1_Bits;
} AT(dPU1);

CodePudding user response:

The @ operator is not standard C; you should find it documented as an extension in the manual for whatever compiler you are using.

The problem here is that static analysis tools need not be aware of such extensions.

Your compiler may offer an alternative method of locating objects that will not trouble the static analysis parser. For example the IAR compiler supports this extension, but has an alternative #pragma location directive:

#pragma location = 0xF0031
__SFR_EXTERN__ __near __no_init volatile union
{
    TByte         ioPU1;
    TBitfieldByte ioPU1_Bits;
} dPU1;

Since the required behaviour when encountering an unrecognised pragma is to ignore it, your analyser should accept this code.

  • Related