Thread View: gnu.g++.bug
1 messages
1 total messages
Started by Tim Day
Wed, 10 May 1989 10:58
Un-initialized return Strings
Author: Tim Day
Date: Wed, 10 May 1989 10:58
Date: Wed, 10 May 1989 10:58
50 lines
1736 bytes
1736 bytes
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 <stream.h>
#include <String.h>
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads