This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: C++ Static String Causes Segmentation Fault
- From: Ian Lance Taylor <iant at google dot com>
- To: Ben Atkinson <bwa4992 at yahoo dot com>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Wed, 22 Jul 2009 12:50:23 -0700
- Subject: Re: C++ Static String Causes Segmentation Fault
- References: <715546.95389.qm@web110514.mail.gq1.yahoo.com>
Ben Atkinson <bwa4992@yahoo.com> writes:
> void
> UseTheString::StringUsageFunction (const string &TheString,
> string &ReturnString)
> {
> cout << "Test 02" << endl;
> ReturnString = TheString; // Causes the sementation fault.
> cout << "Test 03" << endl;
> }
>
> string StaticString::myString = "The String";
>
> StaticString::StaticString (void)
> {
> cout << "Test 01" << endl;
> stringUsageObject.StringUsageFunction(myString, accessableString);
> cout << "Test 04" << endl;
> }
This effectively requires that StaticString::myString be constructed
before any global StaticString object is created. You have a global
StaticString object in the other source file. You are assuming that
global constructors will be run in a particular order across different
files. C++ makes no such guarantee.
Ian