alloca vs var-len auto arrays

Andrew Klossner andrew at frip.wv.tek.com
Thu Apr 27 08:18:52 AEST 1989


> 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 at relay.cs.net)   [ARPA]



More information about the Comp.unix.wizards mailing list