Mail Archives: djgpp/1997/10/14/19:46:24

From: mert0407 AT sable DOT ox DOT ac DOT uk (George Foot)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Is this a bug ??? or feature ??
Date: 14 Oct 1997 21:07:46 GMT
Organization: Oxford University, England
Message-ID: <620mv2$1kr$>
References: <19971013092045 DOT 160 DOT rocketmail AT send1 DOT rocketmail DOT com>
Lines: 31
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -

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