Today's patches

Russ Allbery eagle at eyrie.org
Sat May 23 23:27:14 UTC 2015


Julien ÉLIE <julien at trigofacile.com> writes:

> I have just checked how these structs are currently used, to confirm
> that it is OK to initialize all of them with 0.
> The initialization is now done this way:
>   ARTHANDLE newart = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

> I hope it is fine this way (that is to say "0" instead of "NULL"
> for pointers is portable enough).

Yup, that's fine.  The only place you can't use 0 (or NULL) is when
passing in a NULL pointer to a variadic function, in which case you need
to explicitly cast it to the appropriate pointer type, such as (char *) 0.
And that's because the compiler can't know the type of the argument.
Here, the compiler knows, and can translate 0 without any difficulty.

A common C convention is to define some preprocessor symbol to the
initializer for the data structure so that you can update it in only one
place if you ever change the data structure (preferrably in the same
header that defines the data structure).  Like, for example,
PTHREAD_MUTEX_INITIALIZER.

-- 
Russ Allbery (eagle at eyrie.org)              <http://www.eyrie.org/~eagle/>

    Please send questions to the list rather than mailing me directly.
     <http://www.eyrie.org/~eagle/faqs/questions.html> explains why.


More information about the inn-workers mailing list