Constant Strings

Go To Last Post
15 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is there any compiler directive that can be used to force gcc to just put defined strings in program memory and not copy them to RAM at start of world.

  FunctionBert("Hello Mum") ;

i.e. I don't want the string to get copied to RAM because the internals of "FunctionBert" know to extract it from program memory.

I appreciate that there are work-arounds, such as separately defining the string explicitly as in program memory, but I am after a compiler option to do what I want by default.

Thanks in advance.

Andy

If we are not supposed to eat animals, why are they made out of meat?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

always a microsecond behind ...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No that's not what Andy's after.

What he (and I) are after is to get the strings emitted by the compiler in the code text section. This will *break* all normal 'C' code that reads these strings as they will expect data instructions to access them.

It does nowever make life much easier if you are porting code with copious diagnostics.

Dave

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Take a look at the avr-libc user manual, the Program Space String Utilities and the FAQ.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jens

Thanks for the link, but it was me that provided the second reply in that thread. :D :D

Eric

Thanks for those pointers too. I aleady have my head around the progmem stuff, but I was rather hoping that there was something one could say to the compiler to put all strings in program space only.

As davebush says, this would be as much use as a chocolate teapot for many applications, but if one were porting an application with verbose diagnostics from a non-Harvard architecture processor (or indeed sharing the source file!) it would be nice to be able have the strings in flash only.

I gather that there is no such facility, so will have to work-around.

Thanks again, folks.
Andy G


p.s. Is it only me who hates Harvard architecture?

It strikes me as being a "great idea" for hardware designers, who don't actually have to write any serious code to run on it.

If we are not supposed to eat animals, why are they made out of meat?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

AndyG wrote:

Eric

Thanks for those pointers too. I aleady have my head around the progmem stuff, but I was rather hoping that there was something one could say to the compiler to put all strings in program space only.

Ah! Now I understand.

AndyG wrote:
As davebush says, this would be as much use as a chocolate teapot for many applications,

Um, ..... it must be one of those "seperated by a common language" issues.... I'm on the other side of the pond, so the analogy is a little lost. :lol:

AndyG wrote:
but if one were porting an application with verbose diagnostics from a non-Harvard architecture processor (or indeed sharing the source file!) it would be nice to be able have the strings in flash only.

I gather that there is no such facility, so will have to work-around.

Unfortunately you are quite correct. GCC, in it's current form, does not understand Harvard Architecture, or different address spaces, for any target.

AndyG wrote:


p.s. Is it only me who hates Harvard architecture?

It strikes me as being a "great idea" for hardware designers, who don't actually have to write any serious code to run on it.

Well, the one advantage I do see, is that you never have to worry about a stray data pointer pounding on your code causing your processor to go out to lunch. But, the disadvantages are having to swap around resources to the different memory addresses, and shoehorning C into Harvard Architecture. I have heard that the C Standard might possibly be updated to better handle this, and I've seen drafts to this effect, but who knows when that will be.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's not exactly a question of Gnu understanding address spaces. On the H8 strings and const data are happliy emitted into a read only data section (destined for flash) that is distingusihed from the initialised data section.

On the (default) AVR set up const data goes into a read only section (and it's up to the programmer to realise this), but strings go into initialised data. What AndyG and I are after is treating strings just like const data.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Then perhaps it would be best to post a bug report (technically enhancement request) at the GCC web site.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

May be a good idea. I was hoping that there was already an appropriate option.

It's obviously an AVR code generation specific, does that go to the main web site (wherever that is)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please subscribe to the avr-gcc users list, read its archives, and
discuss this issue there. (Actually, it's already been discussed to
death, and it's best if you read Svein Seldal's article about the
memory-space implementation options, including the thread that
eventually followed.)

No, even though GCC can handle putting constant strings into R/O
memory, this will only work for von Neumann arch CPUs. For Harvard
CPUs, you cannot do this without breaking the C standards
compatibility at all (since you could not pass these pointers to the
standard functions from ), *and* GCC by now cannot handle
the different memory regions from Harvard CPUs at all (Svein considers
to add this feature, eventually, most likely in a way that will adhere
to the C standard extension Eric mentioned), so GCC later simply
wouldn't know the string is actually in ROM where it has to issue a
completely different instruction to fetch it.

What you're describing works pretty well for setups where the OS'es
MMU performs the distinction between R/O and R/W memory (as it's the
case for our typical universal computers these days), or for von
Neumann MCU architectures where the distinction is done by placing the
respective data into a completely different offset of the same (large)
address space, as it's apparently the case for the H8 but also for the
TI MSP430 MCU. In both situations, the compiler later doesn't have to
know the data are actual in ROM since it can still use the same
instructions to read them.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Eric

I assume that you left-pond folks call the container in which tea is brewed a "teapot"? Imagine how much use one would be if it were made from chocolate.

Similarly - as much use as...

An ashtray on a motorbike.
A sponge leg in the rain.
A two-bob watch. (from before 1971 - a mechanical wristwatch that only cost 15 cents)

Cheers
A

If we are not supposed to eat animals, why are they made out of meat?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

AndyG wrote:
Eric

I assume that you left-pond folks call the container in which tea is brewed a "teapot"? Imagine how much use one would be if it were made from chocolate.

Similarly - as much use as...

An ashtray on a motorbike.
A sponge leg in the rain.
A two-bob watch. (from before 1971 - a mechanical wristwatch that only cost 15 cents)

Oh I could think of a use: how about eating it? :) Kinda like a chocolate bunny at Easter... :wink:

A "sponge leg" :?:

How much would that two-bob watch cost now? 10 quid? :lol:

The ashtray bit though is pretty funny.

Left-ponder? :lol:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

AndyG wrote:
Is there any compiler directive that can be used to force gcc to just put defined strings in program memory and not copy them to RAM at start of world.
Andy

I usually dont read the gcc forum because I use the imagecraft compiler, but right in the compiler options dialog there is a box for 'all strings in flash' and the lib has cprintf that takes pointer to const arg as well as printf which needs pointer to non const arg.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I usually dont read the gcc forum because I use the imagecraft compiler, but right in the compiler options dialog there is a box for 'all strings in flash' and the lib has cprintf that takes pointer to const arg as well as printf which needs pointer to non const arg.

Thanks. That's just what I want. I suppose that's what you get if you pay money for a compiler. :D


Quote:

Oh I could think of a use: how about eating it? Kinda like a chocolate bunny at Easter...

A "sponge leg"

How much would that two-bob watch cost now? 10 quid?

The ashtray bit though is pretty funny.

Left-ponder?

General American vs European banter on (say) alt.usage.english flippantly refers to the Atlantic as the big pond. Hence left-pond vs. right-pond styles of English.

Chocolate Easter bunniess at my parents' newagency were usually made by Lindt and I got the broken ones. Funny how many mysteriously "broke" in the stock room.

Imagine a prosthetic limb made of sponge and the effect on the wearer if it got wet.

The difference these day is that you would expect a £10 watch (electronic) to actually work! And keep much better time than a 30-year-old watch that cost a fortune! Impressed that you know that the true currency of the UK is the "quid", though. Next you'll be telling me you understand rhyming slang.

Glad you liked the ashtray analogy too.

Cheers
A

If we are not supposed to eat animals, why are they made out of meat?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


AndyG wrote:

General American vs European banter on (say) alt.usage.english flippantly refers to the Atlantic as the big pond. Hence left-pond vs. right-pond styles of English.

I knew of the "big pond" reference, just not about the "left" and "right" references. :lol:

AndyG wrote:

Imagine a prosthetic limb made of sponge and the effect on the wearer if it got wet.

I think somebody else has already imagined something similar. :shock:

AndyG wrote:

Impressed that you know that the true currency of the UK is the "quid", though.

We get enough British movies and television shows to pick up "some" things. :)

AndyG wrote:

Next you'll be telling me you understand rhyming slang.

Actually, I've heard of it and read some examples. Cockney, correct? It would take me a while to learn all the various phrases. I don't know if this fits or not, but in the recent news what with Margaret Thatcher's son in hot water in South Africa is it? I heard that his other "partners" were referring to him as "Scratcher". When I heard that I thought that this might be a perfect example of rhyming slang.