delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/13/07:02:06

Date: Mon, 13 Oct 1997 15:00:51 +0300 (MSK)
From: Alex Baldin <pipen AT olvs DOT miee DOT ru>
To: djgpp AT delorie DOT com
Subject: Re: Is this a bug ??? or feature ??
In-Reply-To: <19971013092045.160.rocketmail@send1.rocketmail.com>
Message-ID: <Pine.LNX.3.95.971013145522.13171A-100000@olvs>
MIME-Version: 1.0

Hi!
Try compile with '-fwritable-strings', this should make what do you want.

Alex Baldin
pipen AT olvs DOT miee DOT ru

On Mon, 13 Oct 1997, Guan Foo Wah wrote:

> Check the program out below
> 
> 
> //starts here-------------------------------------------------------
> #include <stdio.h>
> 
> char *num[] = {
>     "one",      //line 4
>     "one",      //line 5 :- this string exactly the same as line 4
>     "three",
>     "four"
> };
> 
> char *id[] = {
>     "ten",
>     "two",
>     "one",      //line 13 :- exactly same as line 4 and 5
>     "F16",
>     "DJGPP"
> };
> 
> void main (void)
> {
>     //prints the address of the 3 variables 
>     printf ("Address : %p %p %p %p\n", num[0], num[1], id[2]);
> 
>     //prints the value of the 3 variables before modifying
>     printf ("Value before modifying : %s %s %s\n", num[0], num[1],
> id[2]);
> 
>     //modify one of the 3 variables
>     num[0][0] = 'f';
> 
     //prints the value of the 3 variables after modifying
>     printf ("Value after modifying  : %s %s %s\n", num[0], num[1],
> id[2]);
> }
> 
> //ends here-----------------------------------------------------------
> 
> 
> This is the output compiled on the DJGPP compiler (using BNU281B.ZIP)
> 
> Address : 155b 155b 155b
> Value before modifying : one one one
> Value after modifying  : fne fne fne
> 
> 
> 
> and this is the output compiled on the TURBO C v3.0
> 
> Address : 00BC 00C0 00D7
> Value before modifying : one one one
> Value after modifying  : fne one one
> 
> 
> 
> >From the program output compiled on the DJGPP compiler, it seems that
> num[0], num[1] and id[2] share the same location memory. Why is this
> so ??
> When line 4 in the code which is "one" is replaced with "one ", the
> output
> will change to the one below.
> 
> Address : 155f 155b 155b
> Value before modifying : one  one one
> Value after modifying  : fne  one one
> 
> This time, num[1], and id[2] share the same memory location.
> Can anyone please tell me how to make those three variables not to
> share
> the same memory location ?? This is important in my project which I am
> currently working on.
> 
> 
> 
> 
> 
> _____________________________________________________________________
> Sent by RocketMail. Get your free e-mail at http://www.rocketmail.com
> 

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019