On 7/6/14 10:48 PM, Royce Pereira wrote:
> Thank you, Johann,
> 
> So for the 1st myString , both pointer and elements are in ROM.
> But for the 2nd, the pointer is in RAM and the elements in ROM.


Close: in the 1st example, there is no pointer, only the array of
elements. This is a distinction that usually doesn't matter in C, but
it's a key distinction here.

The 1st example tells the compiler to allocate space for only one thing,
the array of characters. If you implicitly cast "myString" to a pointer
in an expression (a function argument, etc.), the resulting pointer
points to the first element in the array. But that pointer is just an
intermediate value, it's not actually stored in flash.

In the 2nd example, the compiler is told to allocate space for *two*
objects: the string literal (an array of characters), and a pointer
variable whose initial value is the string (that is, a pointer to its
first element). Either of those could be in RAM, or flash, or eeprom,
depending on the type qualifiers you use. If you wanted to, you could
take the address of the pointer and have a valid (char **). Or you can
update the pointer to point to somewhere else, if it isn't in
difficult-to-write-to flash memory.




_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Reply via email to