[Flac-dev] include/share/alloc.h

Erik de Castro Lopo erikd-flac at mega-nerd.com
Tue Sep 11 00:39:41 PDT 2007


Josh,

I noticed the recent addition of the above file. In that file you have
things like:

    static void *safe_malloc_(size_t size)
    {
        /* malloc(0) is undefined; FLAC src convention is to always allocate */
        if(!size)
            size++;
        return malloc(size);
    }

Did you meant to have an "inline" in there to make it:

    static inline void *safe_malloc_(size_t size)

By making them static functions, it means that (in C at least, not sure
about C++) every object file gets a copy of these functions whether they
are used or not. It also results in a bunch of warning messages like:

    ../../include/share/alloc.h:51: warning: 'safe_calloc_' defined but not used
    ../../include/share/alloc.h:68: warning: 'safe_malloc_add_3op_' defined but not used
    ../../include/share/alloc.h:79: warning: 'safe_malloc_add_4op_' defined but not used
    ../../include/share/alloc.h:115: warning: 'safe_malloc_mul_3op_' defined but not used
    ../../include/share/alloc.h:128: warning: 'safe_malloc_mul2add_' defined but not used
    ../../include/share/alloc.h:138: warning: 'safe_malloc_muladd2_' defined but not used
    ../../include/share/alloc.h:148: warning: 'safe_realloc_add_2op_' defined but not used
    ../../include/share/alloc.h:156: warning: 'safe_realloc_add_3op_' defined but not used
    ../../include/share/alloc.h:167: warning: 'safe_realloc_add_4op_' defined but not used

In C (certainly C99, probably also C89) functions that that are defined
"static inline" are inlined if used and ignored (ie no warnings) if not
used.

Is this stuff still a work in progress?

Erik
-- 
-----------------------------------------------------------------
Erik de Castro Lopo
-----------------------------------------------------------------
"Code is more often read than written and thus making it
readable is more important than making it writable."
-- Marcin 'Qrczak' Kowalczyk


More information about the Flac-dev mailing list