Paul Eggert <egg...@cs.ucla.edu> writes:

> Here is that macro's implementation, in case you don't want to bother to
> look it up:
>
> /* With -Dlint, avoid warnings from gcc about code like mbstate_t m = {0,};
>    by wasting space on a static variable of the same type, that is thus
>    guaranteed to be initialized to 0, and use that on the RHS.  */
> #define DZA_CONCAT0(x,y) x ## y
> #define DZA_CONCAT(x,y) DZA_CONCAT0 (x, y)
> #ifdef lint
> # define DECLARE_ZEROED_AGGREGATE(Type, Var) \
>    static Type DZA_CONCAT (s0_, __LINE__); Type Var = DZA_CONCAT (s0_, 
> __LINE__)
> #else
> # define DECLARE_ZEROED_AGGREGATE(Type, Var) \
>   Type Var = { 0, }
> #endif

GCC also suppresses this warning if there are any designated
initializers, e.g.:
        Type var = { .member = 0 };

One could thus do something like this:
        #ifdef __GNUC__
        #define ZERO_INITIALIZER(MEMBER) { .MEMBER = 0 }
        #else
        #define ZERO_INITIALIZER(MEMBER) { 0 }
        #endif

        Type var = { ZERO_INITIALIZER(member) };

It probably needs some refinement, but this looks nicer to me, at
least.
-- 
Ben Pfaff 
http://benpfaff.org



Reply via email to