malloc.h is still legitimate after all

pfgshield-freebsd at pfgshield-freebsd at
Tue Feb 21 10:49:49 PST 2006

I was porting some parts of COIN-OR (some Operations Research packages
opensourced by IBM a while ago), and when I was happily suggesting that all
occurences of malloc.h should be removed and/or replaced with stdlib.h I got
this reply:

The mallinfo struct that ReportMemory uses is defined in malloc.h, and not
brought in by stdlib.h. 

I'm testing on AIXv5.1, __STDC__ is defined, and "struct mallinfo" is unknown
if I don't include malloc.h. 

I don't know enough about the different flavors of UNIX (System V, POSIX, BSD?)
to know what to do that satisfies all. 

The AIX docs say 

  "The mallopt and mallinfo subroutines are provided for source-level
compatibility with the System V malloc subroutine " 

The gnu gcc docs say 

"This function and its associated data type are declared in `malloc.h'; they
are an extension of the standard SVID/XPG version." 

So malloc.h will no be removed from the package but rather it will be undef'd
__FreeBSD__ and the package will still work on FreeBSD. I doubt we will ever
add these extensions, but there's also a glibc port for FreeBSD now so maybe
__FreeBSD__ is not the correct variable here.

I personally think the FreeBSD port's people have contributed greatly to clean
inappropiate uses of malloc.h in the software world, but perhaps an error is
too drastic and we should fall back to a warning.



     Pedro F. Giffuni
     M. Sc. Industrial Eng. University of Pittsburgh
     Mech. Eng.      Universidad Nacional de Colombia
Yahoo is powered by FreeBSD


Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB

More information about the freebsd-standards mailing list