Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: Problems with sting constants and gcc -On

2005-10-18 by Guillermo Prandi

Robert Adsett said:

> the compiler could quite legitimately optimize myfunc out of 
> existence.  Even if it wasn't declared as a static function the 
compiler 
> could optimize the call away and leave the hook for any external 
callers. I 
> was sort of assuming you actually did something with the string, 
otherwise 
> how would you notice?  Checking for a Copyright in the image maybe?
> 
> Robert

Sort of; when I start working with a new compiler/environment I go in 
little steps. I did a small test and I was amazed I didn't see my 
string in the image. Then I came up with these tests and didn't 
expect the optimizer to be so aggresive.

Of course it is not a matter of const or not, since non-constant 
predefined strings must first be placed in ROM in order to be copied 
to RAM on startup. I was looking directly at binary the image, which 
must hold both kinds of string.

Tom Walsh said:

> Well, there is always objdump: 'arm-elf-objdump -d -S -x -s 
<filename>.o'

Thanks, Tom... I was looking at the .lst, .lss and .hex files, which 
are quite similar. ;)

Sten says:

> why you do you declare a string in that way?
> char * f = "Hello";

It is indeed different to declare the string this way. With the above 
method I could do strange things like:

char * n = c;
*(c++) = 'P';

printf("%s-%s",n,c);
>>> Pello-ello

Of course it is not what I intended (I'd try to avoid such 
programming methods whenever possible). I just did it that way 
because I learned it that way so many years ago and now it's an habit.

And no, it was not the compiler that was confused; it was me. :)

Guille

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.