This is the mail archive of the
mailing list for the GCC project.
signal 11 generating problem, was: Further observations regarding alloca on i586-pc-linux-gnu
- To: Martin von Loewis <martin at mira dot isdn dot cs dot tu-berlin dot de>
- Subject: signal 11 generating problem, was: Further observations regarding alloca on i586-pc-linux-gnu
- From: Joerg Pommnitz <pommnitz at darmstadt dot gmd dot de>
- Date: Tue, 25 Aug 1998 12:25:11 +0200
- CC: egcs at cygnus dot com, egcs-bugs at cygnus dot com
- Organization: GMD-IPSI
- References: <email@example.com> <199808221724.TAA14230@jolan.ppro> <19980823043600.A4080@dot.cygnus.com> <35E188FE.BE0D57FA@darmstadt.gmd.de> <199808242238.AAA00565@mira.isdn.cs.tu-berlin.de> <35E1EDFF.1021743E@darmstadt.gmd.de> <199808250624.IAA00271@mira.isdn.cs.tu-berlin.de>
Martin von Loewis wrote:
> > a) allocate heap memory inside the function. Disadvantage: needs
> > explicite release.
> I'd say auto_ptrs are there for you, no? Somebody correct me, but it
> seems that
> void f(char * = std::auto_ptr<char*>(new char));
> is valid C++, and gives you memory that will live slightly longer than
> the call to f, and will then be automatically deallocated.
> You did not say how long you need the memory: If you need automatic
> deallocation when the caller of f returns, you can return an auto_ptr
> from f.
I had thought about auto_ptr before, but the SGI STL in egcs-1.0.x
disables <memory>. Alloca seemed to be a much easier solution.
Returning an auto_ptr is not really an option. According to Stroustrup,
"The C++ Programming Language" 3rd Edition page 368, auto_ptr does not
contain a cast operator to its element type.
However, the following program does what I want:
xx (const auto_ptr<char> &c = auto_ptr<char>(new char))
return strncpy (c.get (), "Hello World!", 20);
cout << xx () << endl;
<sgimemory> is the <memory> include file provided by the current
SGI STL implementation (don't know the exact version number, but
it was current as of 1 week ago).
Now the reason this has been sent to egcs-bugs, too. My original version
of the above program looks like this:
template <int i = 20> char *
xx (const auto_ptr<char> &c = auto_ptr<char>(new char[i]))
return strncpy (c.get (), "Hello World!", i);
cout << xx () << endl;
This version crashes gcc version egcs-2.90.27 980315 (egcs-1.0.2
with g++: Internal compiler error: program cc1plus got fatal signal 11
Can somebody test this with egcs-1.1, please?
GMD-IPSI, Dolivostr. 15, Zimmer 120, D-64293 Darmstadt
+49-6151-869-786 (Phone), -818 (FAX)