bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: in-memory representation of NULL pointers?


From: Ben Pfaff
Subject: Re: in-memory representation of NULL pointers?
Date: Fri, 23 Apr 2010 16:45:22 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

Paul Eggert <address@hidden> 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

[Prev in Thread] Current Thread [Next in Thread]