Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!ames!lll-winken!uunet!tektronix!orca!tekecs!frip!andrew From: andrew@frip.wv.tek.com (Andrew Klossner) Newsgroups: comp.unix.wizards Subject: alloca vs var-len auto arrays Message-ID: <11344@tekecs.GWD.TEK.COM> Date: 26 Apr 89 22:18:52 GMT References: <157@dftsrv.gsfc.nasa.gov> <10013@smoke.BRL.MIL> <8184@chinet.chi.il.us> <1250@frog.UUCP> <564@aablue.UUCP> <1883@thor.acc.stolaf.edu> <15945@rpp386.Dallas.TX.US> <10090@smoke.BRL.MIL> <8261@chinet.chi.il.us> Sender: andrew@tekecs.GWD.TEK.COM Organization: Tektronix, Wilsonville, Oregon Lines: 30 > Are there uses of alloca() that can't be handled by variable-length > automatic arrays: > { int n = 10; { char s[n]; } } > which are allowed by GNU cc? Sure: doit() { while (getting_list) { next_list_element = alloca(...); sort next_list_element into list } for (each element in list) { operate on element; } return; /* free all those alloca's */ } > Are there architectures that will not allow you to implement this? No, with compiler assist you can always implement it; but its complexity can approach that of marking all mallocs and teaching the compiler (and longjmp) to call un_malloc_temporaries on each procedure return. -=- Andrew Klossner (uunet!tektronix!orca!frip!andrew) [UUCP] (andrew%frip.wv.tek.com@relay.cs.net) [ARPA]