Xref: utzoo comp.sys.mac.programmer:12279 comp.sources.wanted:10486 Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!mcgill-vision!bloom-beacon!snorkelwacker!think!zaphod.mps.ohio-state.edu!wuarchive!texbell!vector!attctc!torch From: torch@attctc.Dallas.TX.US (Jay Finger) Newsgroups: comp.sys.mac.programmer,comp.sources.wanted Subject: alloca for Think C 4.0: here it is Keywords: alloca Think C Message-ID: <11376@attctc.Dallas.TX.US> Date: 8 Feb 90 22:51:21 GMT Followup-To: comp.sys.mac.programmer Organization: The Unix(R) Connection, Dallas, Texas Lines: 37 About a week ago I requested a copy of alloca for Think C 4.0. I received several descriptions of what alloca is supposed to do, along with the version of alloca in Earle Horton's port of bison to MPW. I also received several requests for whatever I came up with, so here it is. The alloca function below is completely inline: it uses a few more words of memory that way, but since it's inline it doesn't have to jack with the return address or stack frame (from what I've seen ThinkC always puts a LINK instruction at the beginning of the function, even if it's all in assembler and you've got no local variables). I was rather suprised to discover that inline functions must be pascal style functions; a C function would have been better because the return value would be passed back in D0 instead of on the stack. Anyhow, here's the declaration for alloca. You'll probable want to put in a file called "alloca.h" somewhere. I've got bison (not the MPW version; version 1.03 (8/23/89) from osu-cis) up and running after about ten hours of work. I haven't tested it with anything big yet, but this alloca isn't breaking it. ---------------------- cut here -------------------------------------- pascal void *alloca(long size) = { 0x201F, /* MOVE.L (SP)+,D0 ;get size */ 0x5680, /* ADDQ.L #3,D0 ;make it a multiple of 4 */ 0x0240, 0xFFFC, /* ANDI.W #-4,D0 */ 0x9FC0, /* SUB.L D0,SP ;allocate it */ 0x2F0F /* MOVE.L SP,-(SP) ;return value on stack */ }; ---------------------------------------------------------------------- Jay Finger, {ames,mit-eddie}!attctc!torch ames!torch@attctc