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]

Re: alloca()



# I have cygwin32 and gcc/g77 and use it to compile some FORTRAN code.  Does
# anyone know where alloca() comes from?
# I heard that alloca() is built-in, but does that eventually calls something that
# is inherent to MICROSOFT or Kernel32 libraries?

I recently looked into this as part of our Synergist project, and I as far
as I could muster (bear in mind I'm working in C, not FORTRAN), the C
libraries declare alloca as:

extern void *alloca(size_t len);

(or similar).

GCC then catches this and uses the builtin instead. My best guess is that
because of the nature of alloca(), it has to be a builtin, or at the
outset, a macro -- I'm not too hot on the exact semantics of function
prolog/epilog code and stack state, but the prospect of reserving memory
on the caller of the current function's stack got me so confused I gave up
:-)

As far as I know, all the other C compilers do pretty much the same thing
(including MSVC++, Borland C++, and so on).

As g77 uses gcc as it's back end, I'd guess that declaring a function
called alloca using C calling/naming conventions (how you do this in
FORTRAN I have no idea), and let the compiler manage it. If you get link
errors, I've missed something, and if it just crashes horribly when you
run your program, it's something to do with the state that g77 puts the
stack into.

If anybody could shed any more light onto alloca(), I'd like to feast on
you knowledge :-)

Hope this helps (at all!)

-- 
Mo McKinlay                                T: +44 (0) 709 22 55 05  x1
Chief Software Architect                   F: +44 (0) 709 22 55 05  x3
inter/open                                 E: mmckinlay@labs.interopen.org
A division of Bekon Marketing Limited      W: http://www.interopen.org


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