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

Other const in const structure definition

Hi all,

I have a small issue with a definition with arm C compiler regarding constants.
In an assembly code I define a constant with :

Version EQU 0x01000100

In my main C file I import this const by :

extern unsigned int const Version;

Now my problem is to put this const in another const based on a struct :

const myType titi = { ..., // blabla Version, ... // blabla
};

The compiler gives an error :
Main.c(60): error: #28: expression must have a constant value
But it's a constant !!!

Since my goal is to avoid multiple definition of same constant in severaal files, I'm looking for a solution to solve this problem.

Thanks by advance !

Parents
  • In my main C file I import this const by : extern unsigned int const Version;

    I'm afraid, this will do you no good. In effect, EQU is equivalent to #define, so you cannot export this value outside the assembly source file. The linker will fail to find the Version symbol.

    The compiler gives an error : Main.c(60): error: #28: expression must have a constant value
    But it's a constant !!!

    Even if the extern declaration worked, this construct will not. You are right, Version is a constant in some sense. But the language standard reqires that an initializer contains 'constant expressions' only (the error message could reflect that fact more explicitly.) A 'constant expression' is something very specific and is defined by the standard. Version is not a constant expression.

    Since my goal is to avoid multiple definition of same constant in severaal files, I'm looking for a solution to solve this problem.

    It would be nice if you could have a file containing the version number that could be included in both C and assembly source files. Try this:

    infocenter.arm.com/.../index.jsp

Reply
  • In my main C file I import this const by : extern unsigned int const Version;

    I'm afraid, this will do you no good. In effect, EQU is equivalent to #define, so you cannot export this value outside the assembly source file. The linker will fail to find the Version symbol.

    The compiler gives an error : Main.c(60): error: #28: expression must have a constant value
    But it's a constant !!!

    Even if the extern declaration worked, this construct will not. You are right, Version is a constant in some sense. But the language standard reqires that an initializer contains 'constant expressions' only (the error message could reflect that fact more explicitly.) A 'constant expression' is something very specific and is defined by the standard. Version is not a constant expression.

    Since my goal is to avoid multiple definition of same constant in severaal files, I'm looking for a solution to solve this problem.

    It would be nice if you could have a file containing the version number that could be included in both C and assembly source files. Try this:

    infocenter.arm.com/.../index.jsp

Children