This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Should this work?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]