Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!CS.UCL.AC.UK!T.Day From: T.Day@CS.UCL.AC.UK (Tim Day) Newsgroups: gnu.g++.bug Subject: Un-initialized return Strings Message-ID: <8905102120.AA29080@AENEAS.MIT.EDU> Date: 10 May 89 10:58:56 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 50 I am rather confused by the following... Most of the time, a String() seems to be the equivalent of a String(""), (as I'd expect), but in the below code attempting to output an unitialized String returned from a function as a String causes a segmentation fault, which weird since normally uninitialised Strings, and functions returning Strings, work fine. It also seems odd that returning a StrTmp should fix the problem. (As will always declaring String bleah; as String bleah(""); ) ------------------------------ #include #include String hot() // Returning un-init. String as String bombs { String bleah; return bleah; } StrTmp digital() // ..but returning it as StrTmp is OK { String bleah; return bleah; } String dog() // ..as is returning it as String, once loaded { String bleah; bleah=String("WOOF"); return bleah; } main() { if (String() == String("")) cerr << "Uninitialised string == empty string\n"; if (String() != String("")) cerr << "Uninitialised string != empty string\n"; cerr << "'" << String("") << "'\n"; // OK cerr << "'" << String() << "'\n"; // OK cerr << "'" << dog() << "'\n"; // OK cerr << "'" << digital() << "'\n"; // OK cerr << "'" << hot() << "'\n"; // Ouch! exit(0); } ------------------------------- Tim