Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!mcsun!unido!opal!net From: net@opal.cs.tu-berlin.de (Oliver Laumann) Newsgroups: comp.lang.c Subject: Re: scope of malloc Message-ID: <2182@kraftbus.opal.cs.tu-berlin.de> Date: 10 Nov 90 16:23:05 GMT References: <1990Nov07.134942.7355@virtech.uucp> <1990Nov7.234315.15508@athena.mit.edu> <3729@skye.ed.ac.uk> <14413@smoke.brl.mil> Reply-To: net@tubopal.UUCP (Oliver Laumann) Organization: Technical University of Berlin, Germany Lines: 43 In article <14413@smoke.brl.mil> gwyn@smoke.brl.mil (Doug Gwyn) writes: > In article <3729@skye.ed.ac.uk> richard@aiai.UUCP (Richard Tobin) writes: > >You have the choice of rejecting machines or compilers with such serious > >deficiencies as making alloca() impossible. > > What nonsense. Being unlike a VAX is hardly a "serious deficiency". I'm not aware of any plausible reason why vendors should omit something as useful and simple to implement as alloca() from their UNIX systems. Yes, I know that alloca() may not work with certain existing C compilers, but why, for instance, can't vendors with such types of compilers add an option to support alloca() (like, e.g. Greenhills have done with their C compiler) or implement alloca() as a built-in function (like the SunOS cc does)? You also keep mentioning the argument that alloca() is not needed. If this is true, then how do you make sure that in the following function, which invokes another function that is supplied by user, the memory is freed in case the user-supplied function doesn't return (i.e. invokes longjmp())? -- void wrapper (callback) void (*callback)(); { char *p; ... p = malloc (...); /* do something, then call user-supplied function */ callback (); /* do something */ free (p); } Note that the implementor [implementer?] of the function "wrapper" has no control over what "callback" does; "callback" is supplied by the module's user. Yes, I know that there do exist methods to solve problems like this without using alloca() (I myself had to invent one for Elk, which makes heavy use of alloca()), but a what price? -- Oliver Laumann, Technical University of Berlin, Germany. pyramid!tub!net net@TUB.BITNET net@tub.cs.tu-berlin.de