This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ERROR 247 "non-address/-constant initializer"

Hi there,

I'm using the C51 compiler version 5.5. I'm trying to use the following construct:

#define SYSPTR_LOCAL_CODE 0x40
#define MM0MNDEF_BANK 0x02

const char Str[] = "STRING";

typedef struct
{
byte bType;
byte bHighO;
byte bLowO;
} MakeSysPtr;

#define MakeSysPtr_I( T, B, O ) { ( T | B ), ((word)O >> 8), ((word)O & 0x0FF) }

typedef struct
{
byte bKeys;
MakeSysPtr sLeft;
} MakeKeyDef_T;

const MakeKeyDef_T KEY_DEF =
{
ALL_SOFT_KEYS,
MakeSysPtr_I( SYSPTR_LOCAL_CODE, MM0MNDEF_BANK, Str )
};
The compiler generates the the error message listed in the summary on the line were we use the MakeSysPtr_I ( initializer for the MakeSysPtr structure ). Could someone point out why we're getting this error. I have no problems compiling this piece of code with Visual C or ARM compilers.

Thanks,
Doru.

  • Examine the preprocessor listing, and ensure that your Macro expansions are actually giving what you intended.
    (The option is on the 'Listings' tab in the uVision Project options, or use the PREPRINT command-line option).

    Unfortunately, Keil C51 does not have the option to retain comments in the preprocessor listing. :-(

    If you're still stuck, post the macro expansions - there's no point in everyone trying to do the preprocessor's donkey-work!

    And please use the &ltpre&gt and &lt/pre&gt tags when posting code - see the 'Tips for Posting Messages' link in the sidebar.

    You could also try looking at the MSVC preprocessor listing, to spot any differences.
    the option is something like /EP, which does retain comments :-)

  • I have no problems compiling this piece of code with Visual C

    Have you set your VC to strict ANSI 'C'; ie, disabled all microsoft extensions and C++ features?

  • Under VC I get:

    c:\mydocs\_tempprog\msconsole\msconsole.c(33) : error C2099: initializer is not a constant
    

    Of course if you compile it as a C++ module, this is legal code, and no errors are generated.

  • You are trying to shift a constant 8 times right (Parameter 'O' of your macro), but the value of the constant is unknown at compile time. In the macro invocation the address of the array "Str" is passed as a parameter. The address of "Str" will be fixed later on by the linker. But the linker cannot modify (in your case shift) data. So this macro cannot be processed by the compiler.

    Try storing the address as a 16-bit-pointer. If want access to the bytes of the pointer, use a union.

    HHK

  • Hi there,

    I want to express my gratitude to all those who replied to my post. By defining the pointer as a word instead of a sequence of 2 bytes the shift and AND operations were eliminated and the compiler blissfully accepted the new macro.
    Thanks a lot,

    Doru.