Date: Wed, 15 Oct 1997 18:28:28 +1100 From: Bill Currie Subject: Re: Is this a bug ??? or feature ?? In-reply-to: <19971014223300.SAA13822@ladder01.news.aol.com> To: br5an AT aol DOT com (Br5an), djgpp AT delorie DOT com Message-id: <199710150525.SAA15914@teleng1.tait.co.nz gatekeeper.tait.co.nz> Organization: Tait Electronics Limited MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Comments: Authenticated sender is Precedence: bulk On 14 Oct 97 at 22:33, Br5an wrote: > Guan Foo Wah wrote: > snip: > >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 > [snip] > > Guan Foo Wah, > I can't be sure without experimenting some but it sounds like > the compiler > is optimizing duplicate strings. You will find this is an option This is correct. > with Turbo C++ 3.0 (Options / Compiler / Code Generation). For > now all I can suggest is to declare your arrays, and then to set > there contents later in the code (inside main?) and see if that > helps. Hopefully someone else may come through with how to disable > the optimization (if that's the case) or with another idea. Simple, don't use pointers, use actuall arrays, eg: char num_1[]="foo"; char num_2[]="foo"; char num_3[]="foo"; char *num[]={num_1,num_2,num_3}; int main() { int i; for (i=0; i<3; i++) { printf("%p %s\n",num[i],num[i]); } strcpy(num[0],"bar"); for (i=0; i<3; i++) { printf("%p %s\n",num[i],num[i]); } return 0; } Will give you the exepected results; Bill -- Leave others their otherness.