> In gcc you can do the following:Ah, so it segmentation faults if a regression test fails. That's also a
> char *p = "ABC";
> p = 'a';
> The compiler will not complain but the program will crash with
> Segmentation fault (at least gcc 4.6.3 on my amd64 machine). gcc puts
> literal strings in ro section ( .section .rodata gas directive).
> Interesting that
> "ABC" = 'a';
> throws the "warning: assignment of read-only location ‘"AAA"’
> [enabled by default]" warning.
way to fail. (gcc-torture-execute-20051104-1.c)
And which of these options are used in our host regression tests? Because
> You can use -Wwrite-strings command line option to turn "warning:
> initialization discards ‘const’ qualifier from pointer target type
> [enabled by default]" warnings on or use -fno-const-strings to put
> strings in normal (no ro) section.
I don't see the warning.
So it seems we agree to disagree with the standard! String literals should
> I don't know what is written in the standard but IMHO it is better that
> the compiler complains when the constant literal string is assigned to
> non-constant pointer since it (potentially) causes the run time error
> (which is never shown in sdcc case).
> Putting literals strings into rw memory by default doesn't make sense in
> embedded systems since it is an overhead in RAM, ROM and instruction
> cycles consumption.
> An option would be to implement -fno-const-strings in sdcc too, so the
> user can choose where the string literals are allocated...
> And now the answer to your question from my point of view: in sdcc
> string literal is constants an the compiler should throw an error when
> assigning it to a non constant char pointer.
be constant. And warnings should be given. But then I propose to change
the gcc tests to conform and not use char *s = "123" in there.
> On 25. 10. 2012 01:06, Maarten Brock wrote:
>> Hi all,
>> In recent regression tests there are a few warnings about pointers
>> their const qualifier in code like this:
>> char *s = "abc";
>> Now my question is if this "abc" string literal is constant or not?
>> SDCC thinks it is because it likes to put it in unmodifiable code memory
>> But GCC thinks it's not. It even allows *s='A'; So apparently it didn't
>> even bother to put it in a write-protected segment for the MMU.
>> Can anyone point to the definitive answer?
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
sdcc-devel mailing list