Why the G_calloc()

Chuck Ehlschlaeger chuck at geo.swf.uc.edu
Thu May 9 08:00:00 EDT 1996


???2?52pm?@bnr.ca>
content-type: text/plain; charset=us-ascii
organization: University of Illinois at Urbana
mime-version: 1.0
reply-to: grassu-list at pandora.cecer.army.mil
newsgroups: info.grass.user
originator: daemon at ux1.cso.uiuc.edu




> BTW out of curiosity does anyone know why the GRASS
> developers felt the need to reimplement there own
> version of calloc (and malloc, strcat etc)

Michael Shapiro can explain this better than me (and maybe correctly to boot)_,
but here goes:

G_malloc(), C_calloc(), etc exist to give GRASS better error control for their
functions. If you use G_malloc() and the computer runs out of memory,
G_malloc() will send the appropriate information to G_fatal_error().
G_fatal_error is the "proper" way to exit a GRASS program that fails.
Otherwise, good programming would require the programmer to write:

Buf = malloc( G_window_cols() * sizeof( CELL));
if( Buf == NULL) {
        printf("%s: Ran out of memory\n", G_program_name());
        exit( /* the proper "this program failed" number */)
}

instead of:

Buf = G_malloc( ...)

chuck

-- 
 Charles Ehlschlaeger, Assistant Research Professor     chuck at geo.swf.uc.edu
 Department of Geography (131)                            work: 513-556-2849
 University of Cincinnati                                 fax:  513-556-3370
 Cincinnati, OH 45221                           http://geo.swf.uc.edu/~chuck





More information about the grass-user mailing list