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

assign an absolute memory location

I am kind of confused about using the _at_ keyword to assign a specific address to a variable.

so for example :

extern xdata char variable _at_ 0x000f;

it fills 3 bytes in xram . can any one explain how is the compiler handling these sequence. Thank you !

Parents
  • ...that does not make whatever module the variable is in know where to put it

    That's quite a common newbie misunderstanding of 'extern'.

    Despite your protestation, Jack, it seems that Erik was right this time around. Have you noticed the warning generated by the RealView compiler?

Reply
  • ...that does not make whatever module the variable is in know where to put it

    That's quite a common newbie misunderstanding of 'extern'.

    Despite your protestation, Jack, it seems that Erik was right this time around. Have you noticed the warning generated by the RealView compiler?

Children
  • Despite your protestation, Jack, it seems that Erik was right this time around.

    Let's look at what he actually said:

    extern xdata char variable _at_ 0x000f;

    the _at_ must be in the declaration of the variable

    Wrong - it must be in the definition of the variable, as it is in the example given.

    not in an extern ref

    Wrong - the example given isn't an 'extern ref'.

    that does not make whatever module the variable is in know where to put it

    Wrong - the toolchain knows exactly where to put it.

    Have you noticed the warning generated by the RealView compiler?

    Your use of a compiler extension in a compiler I am not familiar with is entirely your own problem. I suggest you check the compiler documentation.

  • I think the sardine should change his monniker to Nit Pick

    extern xdata char variable _at_ 0x000f;
    the _at_ must be in the declaration of the variable
    Wrong - it must be in the definition of the variable, as it is in the example given.

    1) definition/declaration can be found as synonyms in any crossword handbook.
    2) an extern is NOT a definition, it is a reference

    not in an extern ref
    Wrong - the example given isn't an 'extern ref'.

    if tha example is not an external reference what is it then?

    that does not make whatever module the variable is in know where to put it
    Wrong - the toolchain knows exactly where to put it.

    obviously it does not.

    Erik

  • "1) definition/declaration can be found as synonyms in any crossword handbook."

    C, however, makes a distinction between the two:

    c-faq.com/.../decldef.html

  • "1) definition/declaration can be found as synonyms in any crossword handbook."

    But, as already noted, we are not talking about crossword puzzles!
    We are talking about the 'C' programming language, where the terms have specific, distinct meanings - and a thorough understanding of the distinction is key to this thread!

    "2) an extern is NOT a definition, it is a reference"

    No, it is not a reference, it is a declaration

  • I stand corrected re verbiage; however the reason I stated for the problem (extern combined with _at_) was correct and the OP changed accordingly and now states "it works".

    Erik

  • I stand corrected re verbiage

    Thank goodness for that.

    however the reason I stated for the problem (extern combined with _at_) was correct and the OP changed accordingly and now states "it works".

    Well actually, the problem reported was this:

    it fills 3 bytes in xram

    And you replied:

    it fills 3 bytes in xram is definitely wrong, but not the issue

    Yet you are now claiming it was intended as a fix for the issue. Can you explain?

  • when the mistake is glaring, I usually provide a hint rather than a solution (I know that a hint will lead to better understanding if the asker work on the hint), then when both the OP and you gave up I posted

    the _at_ must be ... not in an extern

    and, amazing to you, I am sure, the 3 byte issue disappeared

    Erik

  • Jack, Erik,
    I need to apologize to you. My posted test above was wrong in the sense that when using the RealView compiler, one should make the declaration like this:

    extern int variable __attribute__((at(0x8000))) ;
    

    and not like the original version, which was

    extern int variable __attribute__((__at(0x8000))) ;
    

    when the first one is used - no warning is generated!