Can an address be assigned to a variable in C?

前端 未结 9 2032
孤城傲影
孤城傲影 2021-01-06 05:28

Is it possible to assign a variable the address you want, in the memory?

I tried to do so but I am getting an error as \"Lvalue required as left operand of assignmen

9条回答
  •  臣服心动
    2021-01-06 05:57

    Not portably. But some compilers (usually for the embedded world) have extensions to do it.

    For example on IAR compiler (here for MSP430), you can do this:

    static const char version[] @ 0x1000 = "v1.0";
    

    This will put object version at memory address 0x1000.

提交回复
热议问题