Mail Archives: djgpp/1997/10/14/19:46:24
On Mon, 13 Oct 1997 09:20:45 GMT in comp.os.msdos.djgpp Guan Foo Wah (djgpp AT rocketmail DOT com) wrote:
: 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 ??
It's optimising your strings. People always complain about large exe file
sizes... now you're complaining about efficiency ;). I think I'm right in
saying that reusing strings in this way is optional for a compiler;
clearly djgpp does it and bc does not. I think there is a command line
option to turn this behaviour off; look in the info docs.
: 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.
If you allocate them dynamically, of course, they'll all point at
different copies of the string. E.g.:
char one[] = "one";
char *(num[3]);
...
for (i=0;i<3;i++) { num[i] = strdup (one); }
--
George Foot <mert0407 AT sable DOT ox DOT ac DOT uk>
Merton College, Oxford
- Raw text -