`static foo array[SIZE]' is not `malloc()' (Re: free (NULL);)

Peter da Silva peter at ficc.ferranti.com
Thu May 10 05:05:12 AEST 1990


In article <5804 at buengc.BU.EDU> bph at buengc.bu.edu (Blair P. Houghton) writes:
> Using this function the array test[] will be allocated
> exactly once during the execution of the program, and the
> same value will be returned no matter how many times
> squirl() is called.  If you want two blocks of 100 char's
> simultaneously, this won't work.

Unfortunately, neither will the original proposal:

	char *foo()
	{
		static char *buffer = NULL;

		free(buffer);

		...

		buffer = malloc(...);

		return buffer;
	}

Unless you *like* dereferencing freed pointers, that is.

What it *will* do is let you deal with large objects without chewing up
lots of BSS.
-- 
`-_-' Peter da Silva. +1 713 274 5180.  <peter at ficc.ferranti.com>
 'U`  Have you hugged your wolf today?  <peter at sugar.hackercorp.com>
@FIN  Commercial solicitation *is* accepted by email to this address.



More information about the Comp.lang.c mailing list