🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.next.programmer
Article #484

Re: How are string constants stored in Objective-C?

#484
From: moose
Date: Thu, 06 Aug 1992 17:14
33 lines
1852 bytes
In article <1992Aug5.032444.4006@visus.com> jml@visus.com (Jim Large) writes:
> In article <15mfliINNj9a@darkstar.UCSC.EDU> isbell@cats.ucsc.edu (Art Isbell)  
> writes:
> > const char *aStringPtr = "string";
> > const char aString[] = "string";
> 
> 
> > I've assumed that the memory referenced by aStringPtr is in some read-only
> > heap area.  When aStringPtr is no longer needed, can this memory be freed
> > with free(aStringPtr)?
> 
> NO!  The constant string is not allocated from a heap.  You can't free it,
> and you can't ever change its contents.  (It really is a CONSTANT.)

While you are correct in just about every case, this will make nethack (along  
with other historical programs) a pain to compile and run because nethack needs  
to modify string constants.  But there is a compiler flag, -fwritable-strings,  
which will allow you to modify the string constants.

Straight from the cc man pages

     -fwritable-strings
          Store string constants in the writable data segment and
          don't make them unique.  This is for compatibility with
          old programs that assume they can write into string
          constants.  Writing into string constants is a very bad
          idea; "constants" should be constant.

--
Michael Rutman			|	moose@svcdudes.com
Cubist				|	makes me a NeXT programmer
Software Ventures		|	maker of MicroPhone II
#include <std.disclaimer>
Technical Details
Message-ID: <1992Aug6.171444.24974@svcdudes.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!psinntp!svc!news
References: <1992Aug5.032444.4006@visus.com>

Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.next.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!psinntp!svc!news
From: moose@svcdudes.com
Subject: Re: How are string constants stored in Objective-C?
Message-ID: <1992Aug6.171444.24974@svcdudes.com>
Sender: news@svcdudes.com
Reply-To: moose@svcdudes.com
Organization: Software Ventures, Inc.
References: <1992Aug5.032444.4006@visus.com>
Distribution: na
Date: Thu, 6 Aug 92 17:14:44 GMT
Lines: 33