On 22Jun2019 21:14, vincent lefevre <vinc...@vinc17.org> wrote:
On 2019-06-22 12:40:39 +0200, Oswald Buddenhagen wrote:
On Sat, Jun 22, 2019 at 09:42:36AM +0200, Vincent Lefevre wrote:
>         p->init = (unsigned long) safe_strdup (* ((char **) p->data));
>
> IMHO, the best solution for safety would be to use a union (I think
> that this would require the use of C99 designators for the MuttVars
> initialization). Otherwise check (uintptr_t) -1 <= (unsigned long) -1
> in configure.
>
it's easier to just use !! or put != NULL at the end instead of the cast.

AFAIK, the value itself matters, not just the fact that it is
non-zero.

If I were doing this in Python or any other object oriented language I'd have a special sentinel value of the right type i.e. _not_ some magic -1 value we expect to not match any other pointer-as-integer value and also not NULL, but an actual distinct special purpose (char*).

So how about this:

   #define UNSET_CHAR_PTR "<unset>"

and to use UNSET_CHAR_PTR instead of (uintptr_t)-1 and (unsigned long)-1.

Specificly, this way we (a) avoid doing any casts and (b) avoid any need for a union and its associated cognitive dissonance and (c) avoid a magic number in the code (the -1, in whatever form).

I'm totally serious about this, BTW.

Cheers,
Cameron Simpson <c...@cskk.id.au>

Reply via email to