Re: [cc65] Problem with code compiled as overlay.

From: Ullrich von Bassewitz <uz1musoftware.de>
Date: 2012-01-22 11:56:11
On Sun, Jan 22, 2012 at 03:07:41AM +0100, Groepaz wrote:
> eh, so something like
>
> char *foo = "abc";
>
> foo[1] = 'B';
>
> is undefined?

No. We're talking about string literals. So

        "abc"[1] = 'd';

is legal in the sense that it is translated by the compiler, but the behaviour
is undefined when executed. This has history reasons. String literals were of
type "char*" a long time ago. And since they were actually writable, people
relied on that. Newer versions of the standard could not change the type
without making almost every old source uncompilable, so they kept the type
being "char*" but prohibited writing to the literal. To allow this practice,
which was common in very old sources, some compilers (like gcc) have an option
that places these strings into the data segment.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz@musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Sun Jan 22 11:56:18 2012

This archive was generated by hypermail 2.1.8 : 2012-01-22 11:56:21 CET