[alt.msdos.programmer] Strange misoptimization in Turbo C

pt@geovision.uucp (Paul Tomblin) (02/19/90)

Has anybody seen this?  Has Borland?   Anybody know why it occurs?

I've just received CXL5.1, and was recompiling the demo program with Turbo C
2.0 (with all the patches, I think), and was getting some pretty strange
behaviour.  In the menuing demo, after choosing one of the options that
toggles yes to no, I got a screen full of garbage, and many errors later on
because the string space seemed a little corrupt.  Investigation showed that
the culprit was the following line:

    strcpy(yn,strcmp(yn,"yes")?"yes":" no");

in toggle_yn().  The temporary pointer that should have been pointing to the
string " no", was instead pointing into the middle of some other very long
string.  I tried turning off the questionable optimizations like -Z and even
-O, but to no avail.  It did work, however, if I turned off the "merge
duplicate strings" (-d) option.  I really like the idea of this option,
since it can make quite a difference, so I'd like to know if there is a
patch to fix this.  I've never seen this problem before in any other code
I've compiled.

-- 
Paul Tomblin nrcaer!cognos!geovision!pt or uunet!geovision!pt
Life: Loath it or ignore it, you can't like it.  (Marvin)
(My employer may not agree with my opinions, especially my .signature)