Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!decwrl!pa.dec.com!bacchus!mwm From: mwm@pa.dec.com (Mike (My Watch Has Windows) Meyer) Newsgroups: comp.sys.amiga.programmer Subject: Re: Compiler code (was a flame fest) Message-ID: Date: 2 Apr 91 18:05:00 GMT References: <1991Apr2.100807.13471@ux1.cso.uiuc.edu> Sender: news@pa.dec.com (News) Organization: Missionaria Phonibalonica Lines: 36 In-Reply-To: cs326ag@ux1.cso.uiuc.edu's message of Tue, 2 Apr 1991 10:08:07 GMT In article <1991Apr2.100807.13471@ux1.cso.uiuc.edu> cs326ag@ux1.cso.uiuc.edu (Loren J. Rittle) writes: In article <1991Apr2.002631.22799@mintaka.lcs.mit.edu> rjc@geech.gnu.ai.mit.edu (Ray Cromwell) writes: >In article mykes@amiga0.SF-Bay.ORG (Mike Schwartz) writes: >>>char buf[20]; >>>main() >>>{ >>> char *d=(char *)&buf; >>> const char *s="This is a test\n"; >>> while(*s) { *d++=*s++; } >>>} void main (void) { char *d = (char *)&buf; char *s = "This is a test\n"; // Note I got rid of the const, as // not only is it of questionable // legality under ANSI C (YOU CHANGE THE // VALUE OF s!), but also caused SAS/C // to generate (good, but) strange // (meaning LONG) code. while (*s) *d++=*s++; } Actually, the code is perfectly valid. S is declared as a "pointer to constant", which it is - the string isn't changed. To declare s as a constant, its "char *const s". That would have been invalid.