Path: utzoo!attcan!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!uwm.edu!gem.mps.ohio-state.edu!pacific.mps.ohio-state.edu!tut.cis.ohio-state.edu!ucbvax!hplabs!hpl-opus!hpnmdla!hpmwtd!jeffa From: jeffa@hpmwtd.HP.COM (Jeff Aguilera) Newsgroups: comp.lang.c++ Subject: incorrect inline translation in 1.2 and 2.0 Message-ID: <1520004@hpmwjaa.HP.COM> Date: 26 Oct 89 22:43:35 GMT Organization: HP Microwave Tech. - Santa Rosa, Ca. Lines: 53 C++ generates incorrect code for the following program. The problem exists under versions 1.2, 2.0 beta, and 2.0. Correct code is emitted when the inline specifier is deleted. /*********************************************************************/ //inlinebug.c const char* null(const char* p) { if (p) while(*p) ++p; return p; } inline int length(const char* p) { return null(p)-p; } int snafu() { return length("oops"); } /*********************************************************************/ C++ translates this as follows: /* @(#)<> */ /* < inlinebug.c > */ ... char* null__FPCc(__0p) char* __0p; { if (__0p) while ((*__0p)) ++__0p; return __0p; } int snafu__Fv() { return ((null__FPCc(((char*)"oops"))-((char*)"oops"))); } Although ANSI C permits the two instances of "oops" to share the same read-only address, this is not required, nor is it traditional: A2.6 Strings (Kernighan and Ritchie 2nd ed, p.194) A string literal, also called a string constant, is a sequence of characters surrounded by double quotes, as in "...". A string has type ``array of characters'' and storage class static, and is initialized with the given characters. Whether identical string literals are distinct is implementation-defined, and the behavior of a program that attempts to alter a string literal is undefined. 2.5 Strings (Stroustrup, p.247): A string is a sequence of characters surrounded by double quotes, as in "...". A string has type ``array of characters'' and storage class static, and is initialized with the given characters. All strings, even when written identically, are distinct. 2.5 Strings (Kernighan and Ritchie, p.181) A string is a sequence of characters surrounded by double quotes, as in "...". A string has type ``array of characters'' and storage class static, and is initialized with the given characters. All strings, even when written identically, are distinct. --- jaa