Mail Archives: djgpp/1997/10/15/01:26:23
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.
- Raw text -