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

How to import a constant symbol defined in assembly to C module?

Hi all,

I defined some symbols in my assembly module. But I also need to use them in my C files. I don't want to define it twice at different places. How can I make those constants visible in C file?
For example, I define a constant in .a66 like following,
Kf_100_init equ 20133

What I want to do in a C file is,
freq = tmp * Kf_100_init;

Parents
  • How can I make those constants visible in C file?

    I don't think you can do that at all. The problem is that C doesn't recognize the concept of a "constant" as a linkable object in the first place. I.e. there's no strict equivalent to assembler's "EQU" in C. You can have variables with the 'const' attributes whose value is not allowed to change, but you can't have actual constants with a name but no address, which are defined in another object module rather than being published in its header.

    There are two ways out of this:

    1) Use a compile-time constant instead of linkable symbol. I.e. turn your EQU into a #define found in a header file #include'd by both the assembler and the C code.

    2) Turn your constant from an integer into a pointer, i.e. the address of some non-existant object exported by the assembler. You may run into problems convincing the linker that this non-existant object doesn't interfere with real ones, though.

Reply
  • How can I make those constants visible in C file?

    I don't think you can do that at all. The problem is that C doesn't recognize the concept of a "constant" as a linkable object in the first place. I.e. there's no strict equivalent to assembler's "EQU" in C. You can have variables with the 'const' attributes whose value is not allowed to change, but you can't have actual constants with a name but no address, which are defined in another object module rather than being published in its header.

    There are two ways out of this:

    1) Use a compile-time constant instead of linkable symbol. I.e. turn your EQU into a #define found in a header file #include'd by both the assembler and the C code.

    2) Turn your constant from an integer into a pointer, i.e. the address of some non-existant object exported by the assembler. You may run into problems convincing the linker that this non-existant object doesn't interfere with real ones, though.

Children