home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.3b1
- Path: sparky!uunet!usc!sol.ctr.columbia.edu!destroyer!wsu-cs!uts.cc.wayne.edu!rwilson
- From: rwilson@uts.cc.wayne.edu (Ron Wilson)
- Subject: Re: Lack of libPW.a module
- Message-ID: <1992Aug28.184411.25578@uts.cc.wayne.edu>
- Keywords: libPW PW alloca xmalloc
- Organization: Wayne State University, Detroit Mich.
- References: <1992Aug22.004946.20370@pbhyf.PacBell.COM> <1992Aug25.235036.28469@colnet.cmhnet.org> <1992Aug27.213851.20578@digibd.com>
- Date: Fri, 28 Aug 1992 18:44:11 GMT
- Lines: 36
-
- In article <1992Aug27.213851.20578@digibd.com> steve@digibd.com (Steve Wahl) writes:
- >In article <1992Aug25.235036.28469@colnet.cmhnet.org> res@colnet.cmhnet.org (Rob Stampfli) writes:
- >...
- >>===============================================================================
- >># This is optimized for the Unix PC, it won't work on some other 68k systems.
- >># The "and.l &-4" could be changed to "and.l &-2" if you're only running the
- >># code on the Unix PC. I use this same code when cross-compiling to a 68020
- >># system, thus the longword alignment.
- >>
- >> global alloca
- >>alloca:
- >> mov.l (%sp)+,%a0 # pop return addr
- >> mov.l (%sp),%d0 # get size argument
- >> and.l &-4,%d0 # round size down to long word
- >> sub.l %d0,%sp # allocate by moving stack pointer
- >> mov.l %sp,%d0 # return pointer in d0
- >> lea -4(%sp),%sp # allow caller to pop the arg
- >> jmp (%a0) # return
- >
- >Rob's post mentions that you can't call this alloca() when there's
- >something on the stack. But beware: I believe this aproach also fails
- >if you use register variables in your functions: think about how the
- >compiler saves and restores the registers.
- >
- >--> Steve
-
- The problem is NOT that something is on the stack, but rather using this
- alloca inside an expression that uses the stack will corrupt the stack.
- As for register variables, they shouldn't be affected: Once "you" start
- executing code in the BODY ofa function or a block of code - as opposed
- to executable code imbedded in the definition section - all of the
- variables - including register variables - will be allocated.
-
- As long as you only use alloca() in simple asignment statements - = only,
- not even if ((x = alloca(n)) == NULL) - functions using alloca() should
- work just fine.
-