List Info

Thread: include/share/alloc.h




include/share/alloc.h
user name
2007-09-11 02:39:41
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
_______________________________________________
Flac-dev mailing list
Flac-devxiph.org
http:
//lists.xiph.org/mailman/listinfo/flac-dev

Re: include/share/alloc.h
country flaguser name
United States
2007-09-11 03:22:51
--- Erik de Castro Lopo <erikd-flacmega-nerd.com> wrote:

> 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?

yes.  I would use inline except I thought it is only since
C99 (not
available in C89), so I'm planning to do the same odious
hackery
that's everywhere else.


       
____________________________________________________________
________________________
Pinpoint customers who are looking for what you sell. 
http://searchmarket
ing.yahoo.com/
_______________________________________________
Flac-dev mailing list
Flac-devxiph.org
http:
//lists.xiph.org/mailman/listinfo/flac-dev

Re: include/share/alloc.h
user name
2007-09-11 03:34:33
Josh Coalson wrote:

> yes.  I would use inline except I thought it is only
since C99 (not
> available in C89), so I'm planning to do the same
odious hackery
> that's everywhere else.

Well it is the year 2007 and I for one reckon its time
fully
embrace a standard that is 8 years old .

It does however create a problem for the microsoft platform
where the most commonly used C compiler on that platform is
still not C99 compliant.
 
Erik
-- 
------------------------------------------------------------
-----
Erik de Castro Lopo
------------------------------------------------------------
-----
"Christianity has a nasty habit of ignoring the major
problems of
our time, including overpopulation and exhaustion of
resources,
because  they aren't mentioned in the Bible."
-- Paula L. Craig
_______________________________________________
Flac-dev mailing list
Flac-devxiph.org
http:
//lists.xiph.org/mailman/listinfo/flac-dev

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )