TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: andrew clarke
from: Paul Edwards
date: 1995-09-04 22:17:22
subject: string constants

ac> Hi there.  Why does emx/gcc disallow the modification of string constants?  

Presumably so that they can be stored in the same area of memory
as the program code, and be protected.  I don't know.  The ANSI
Rationale is available from here if you want to see if they
said anything about that.

ac> Or more to the point - why does ANSI/ISO C disallow this?  Tnx.

From memory, they made it implementation-defined whether you could
or not.

ac> 1.0, the following code executes without error.  CLint 1.41 also passed the 
ac> following code with flying colors.

I would imagine it would be hard for lint to detect something
like that.
ac> The following code is a simple work-around for the rule:

ac>     char *str = strdup("Hello world");

Bearing in mind that strdup() is not ISO C.  A better method
would be char str[] = "Hello world";
BFN.  Paul.
@EOT:

---
* Origin: X (3:711/934.9)

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.