avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] String declaration query


From: Wim Lewis
Subject: Re: [avr-gcc-list] String declaration query
Date: Mon, 07 Jul 2014 01:19:19 -0700
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:24.0) Gecko/20100101 Thunderbird/24.6.0

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.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]