string sharing (possible bug?)
Tim Olson
tim at jumpnet.com
Thu Dec 10 03:44:02 UTC 1998
>On 12/9/98 at 5:48 PM, tod.blanchard at kanisa.com (Blanchard, Tod) wrote:
>
>> In practice most C compilers are lax about checking for this and don't
>> produce more than a single read/write data segment. For instance, I just
>> tried that program on Solaris using gcc and it worked exactly as I expected.
>> Not even a warning. Most good C++ compilers generate a warning at
>> initialization warning that a non-const pointer was initialized pointing to
>Hmmmm.....makes me think this is a generic problem with operating system
>design in addition to a language problem.
This goes all the way back to some of the original FORTRAN
implementations. In FORTRAN (up through FORTRAN-IV and FORTRAN-77,
anyway), everything is call-by-reference, and most implementations used a
"constant pool" for literals. The classic mistake would be to pass a
"constant" to a subroutine which ended up modifying that constant --
future uses would then be corrupted:
CALL X(1)
I = 1 + 1
WRITE (6, 10) I
10 FORMAT (1H1, 7H1 + 1 =, I2)
STOP
END
SUBROUTINE X(I)
I = 2
RETURN
END
See <http://catless.ncl.ac.uk/Risks/16.38.html#subj9> for more discussion
on this.
-- tim
More information about the Squeak-dev
mailing list
|