This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Should this work?
- To: egcs at cygnus dot com
- Subject: Should this work?
- From: Joerg Pommnitz <pommnitz at darmstadt dot gmd dot de>
- Date: Thu, 20 Aug 1998 00:22:43 +0200
- Organization: GMD-IPSI
I get a SEGV with the following program under i586-pc-linux-gnu:
#include <cstdlib>
#include <iostream>
class xx {
public:
char *xy (char *c = alloca (18)) {
strcpy (c, "Hello World!");
return c;
}
};
int
main ()
{
xx x;
cout << x.xy () << endl;
}
The idea is to use alloca to allocate memory from the callerīs
stack and to be able to do something like:
printf ("%s %s", x.xy (), x.xy ());
without having to clean up.
Regards
Joerg