Path: utzoo!utgpu!water!watmath!clyde!ima!cfisun!lakart!dg From: dg@lakart.UUCP (David Goodenough) Newsgroups: comp.sources.d Subject: Re: Simulation of 'alloca' -- can it be done in TurboC or MSC? Message-ID: <134@lakart.UUCP> Date: 23 May 88 23:22:23 GMT References: <203@lcuxa.UUCP> Organization: Lake - The systems people Lines: 32 From article <203@lcuxa.UUCP>, by mike2@lcuxa.UUCP (M S Slomin): > Quick question: has anyone worked out a way to simulate the 'alloca' > function in either TurboC or MSC (DOS for those who don't know)? Write it in assembler. I don't know how to do alloca in C in a portable manner. Come to that - since you have to mess with your frame/stack pointer I don't think it can be done in anything other than assembler. Sure can't on a z80. CAVEAT for my z80 implementetion, you are advised NOT TO USE in a complex expression (where temp results need to be stacked) think about it!! .extern _alloca _alloca: pop de pop hl call #neg ; negate argument add hl,sp ; allocate the space push hl push de ; put args back so return works ret ; home we go - hl points to space. This should be fairly easy to convert to 8086 assembler (What, your C compiler can't talk in assembler?? :-) Different segments may be a pain - this space will be in SS:, and I can just see referencing through a 16 bit pointer as DS: UGH!!. Still if you send back a 32 bit pointer SEG:OFFSET or make sure DS: and SS: are the same, you should be flying. -- dg@lakart.UUCP - David Goodenough +---+ | +-+-+ ....... !harvard!adelie!cfisun!lakart!dg +-+-+ | +---+