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

Help me: how to determine constant value at link time?

In ASM51, the following code is every useful:


-------- file1.asm ---------
public MAX
MAX EQU 10

-------- file2.asm ---------
extrn number(MAX)
MOV	A,#MAX

The point is that the constant value of MAX in file2.asm can be determined at link time.

I want the same effect in C51, that's to say, to define a constant as "extern". I have tried a lot of ways. One of them is:

-------- file2.C -----------
extern code MAX;
#define MAX_NUMBER ((unsigned char)&MAX)

C51 is trying to treat MAX_NUMBER as a constant, but the compiled result is much longer than the original one. Is there any better way???

Parents
  • "One year has passed but nobody give me a good answer."

    Well, I'm sorry - I didn't realise I was supposed to drop everything and concentrate on your problem!

    Anyway, think about what the Linker does: it deals with addresses - you define a symbol in 'C', and the Linker fixes its address.
    Therefore, if you want the Linker to give a constant back to 'C', it will be as the address of a 'C' symbol.
    Your 'C' code will have to take the address of the symbol, and interpret that address value as the required constant (probably via a cast).

Reply
  • "One year has passed but nobody give me a good answer."

    Well, I'm sorry - I didn't realise I was supposed to drop everything and concentrate on your problem!

    Anyway, think about what the Linker does: it deals with addresses - you define a symbol in 'C', and the Linker fixes its address.
    Therefore, if you want the Linker to give a constant back to 'C', it will be as the address of a 'C' symbol.
    Your 'C' code will have to take the address of the symbol, and interpret that address value as the required constant (probably via a cast).

Children
No data