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

What is Code memory type

I am using the Cx51 compiler.

I declared a array of pointers to characters as

char code *weekday_names[ ] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };

Thinking it would go into the CODE memory space - it did not, and ended up in DATA
space, causing an address space overflow.

I changed it to

code char *weekday_names[ ] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };

and then it was placed into the CODE space.

Can someone explain the difference between these two ?

Thanks

Parents
  • You have an array of pointers to text.

    So you can decide if you want the array of pointers to be stored in the code memory space.

    Or you can decide that the pointers should point to text stored in the code memory space.

    Or you can decide that both the array of pointers and the text should be stored in the code memory space.

    While the code memory space is very much architecture-specific, you have the same things to consider when playing with the "const" keyword that is part of the C language standard. Do you want that the pointer should be const? Or should it point to const data? Or do you want a const pointer pointing to const data? It's all in the position of the const keyword - or if you use two const keywords.

Reply
  • You have an array of pointers to text.

    So you can decide if you want the array of pointers to be stored in the code memory space.

    Or you can decide that the pointers should point to text stored in the code memory space.

    Or you can decide that both the array of pointers and the text should be stored in the code memory space.

    While the code memory space is very much architecture-specific, you have the same things to consider when playing with the "const" keyword that is part of the C language standard. Do you want that the pointer should be const? Or should it point to const data? Or do you want a const pointer pointing to const data? It's all in the position of the const keyword - or if you use two const keywords.

Children
No data