On Fri, Dec 08, 2000 at 05:25:52PM +0100, Niels Diepeveen wrote:
> SONE Takeshi schreef:
> > alloca() is a built-in function in both GCC and MSVC.
> > (no underscore in GCC)
> > I've been using it without a problem.
> > GCC itself uses it also.
> Thanks! That was the hint I needed. I was working on some code written
> for MSVC, which has _alloca instead of alloca. Now this would not be so
> bad if _alloca didn't exist in the library. The problem is that there is
> something called _alloca() in some standard library that does something
> similar to alloca(). This routine does not seem to follow C calling
> conventions and apparently puts its return address in %eax, instead of
> the pointer to the allocated space. You can imagine the hideous results.
> I don't know if this would be easy to fix, but it would certainly save a
> lot of debugging time when porting MSVC code.
Ok, I see the problem.
_alloca() *is* in libgcc.a, but it is not what MSVC people expect.
It's a support function of gcc, not a 'non-oldname version' of alloca().
_alloca() is called implicitly whenever gcc allocates >4096 bytes in stack.
This simple function:
involves a call to _alloca().
ts1@...$ ~/GCC/bin/i386-mingw32-gcc -S hoge.c
ts1@...$ cat hoge.s
.def _foo; .scl 2; .type 32; .endef
Of cource, it's same when you call alloca() (no underscore) with its
argument more than 4096 (or unknown at compile-time).
IMHO naming it _alloca was Cygnus' fault.
At least, we should have '#define _alloca alloca' in <malloc.h>?