Can an address be assigned to a variable in C?

前端 未结 9 2114
孤城傲影
孤城傲影 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条回答
  •  旧时难觅i
    2021-01-06 05:50

    Use ldscript/linker command file. This will however, assign at link time, not run time.

    Linker command file syntax depends largely on specific compiler. So you will need to google for linker command file, for your compiler.

    Approximate pseudo syntax would be somewhat like this:

    In linker command file:
    .section start=0x1000 lenth=0x100 myVariables
    In C file:
    #pragma section myVariables
    int myVar=10;
    

提交回复
热议问题