delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/05/12/14:19:36

Date: Thu, 12 May 1994 14:09:43 -0400 (EDT)
From: Chris Tate <FIXER AT FAXCSL DOT DCRT DOT NIH DOT GOV>
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: malloc, calloc, free, cfree....

Just to set the record straight, cfree() is *NOT* an ANSI C function.
free() is used to free memory allocated by *either* malloc() or
calloc(), according to the ANSI spec.

Kernighan & Richie, 2e, gives the following in its summary of the
standard ANSI C library functions:

"void free(void *p)
   free deallocates the space pointed to by p; it does nothing if p
   is NULL.  p must be a pointer to space previously allocated by
   calloc, malloc, or realloc."

The only differences between malloc() and calloc() are the exact
way in which the size of the desired blocks are specified (malloc()
takes a size_t expressing the size in bytes of the block, calloc()
takes two arguments - "give me n blocks of size s"), and the fact
that calloc() clears the entire block to zeros before returning.

-- Chris Tate
   fixer AT faxcsl DOT dcrt DOT nih DOT gov

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019