Thread: Re: [PORTS] (void)NULL in macros and aix

Re: [PORTS] (void)NULL in macros and aix

From
darrenk@insightdist.com (Darren King)
Date:
> >
> > 2. This is more like a C issue rather than aix-specific.  The aix compiler complains
> > about assigning the (void)NULL to isnull in the heap_getattr macro.  Changing the
> > (void) to (bool) works and seems like it should be (bool) to match the type of isnull,
> > shouldn't it?
> >
> > *** include/access/heapam.h.org    Sun Jan  4 23:52:05 1998
> > --- include/access/heapam.h    Sun Jan  4 23:52:11 1998
> > ***************
> > *** 101,110 ****
> >   #define heap_getattr(tup, b, attnum, tupleDesc, isnull) \
> >       (AssertMacro((tup) != NULL) ? \
> >           ((attnum) > (int) (tup)->t_natts) ? \
> > !             (((isnull) ? (*(isnull) = true) : (void)NULL), (Datum)NULL) : \
> >           ((attnum) > 0) ? \
> >               fastgetattr((tup), (attnum), (tupleDesc), (isnull)) : \
> > !         (((isnull) ? (*(isnull) = false) : (void)NULL), heap_getsysattr((tup), (b), (attnum))) : \
> >       (Datum)NULL)
> >
> >   extern HeapAccessStatistics heap_access_stats;    /* in stats.c */
> > --- 101,110 ----
> >   #define heap_getattr(tup, b, attnum, tupleDesc, isnull) \
> >       (AssertMacro((tup) != NULL) ? \
> >           ((attnum) > (int) (tup)->t_natts) ? \
> > !             (((isnull) ? (*(isnull) = true) : (bool)NULL), (Datum)NULL) : \
> >           ((attnum) > 0) ? \
> >               fastgetattr((tup), (attnum), (tupleDesc), (isnull)) : \
> > !         (((isnull) ? (*(isnull) = false) : (bool)NULL), heap_getsysattr((tup), (b), (attnum))) : \
> >       (Datum)NULL)
> >
> >   extern HeapAccessStatistics heap_access_stats;    /* in stats.c */
>
> We made if void so that we would stop getting gcc warnings about 'unused
> left-hand side of conditional' messages.  Does aix complain or stop.  If
> it just complains, I think we have to leave it alone, because everyone
> else will complain about bool.

But this is then trying to assign a (void)NULL to isnull, which is a bool (really a char).
IMHO gcc should complain.  Aix gives a severe error since the types don't match.

Maybe better to have a warning than fix it by causing an error.  Gcc just happens to be in
a forgiving mood. What does the C standard say about casting (void) ptrs to other types?

Why not make this a _little_ more legible and compiler-friendly by making it into an
if-then-else block?  Is the ?: operator really saving any ops?

---------

Re: the StrNCpy macro...

The aix compiler complains about trying to assign a (void)NULL to (len > 0).  Can this be
fixed with another set of parens separating the returned dest from the ?: operator?

Like...

(((strncpy((dst),(src),(len)),(len > 0)) ? *((dst)+(len)-1)='\0' : ((char)NULL)),(dst)))
 ^                                                                             ^

This gets the return value back doesn't it?  And changing to a (char)NULL makes the
compiler happy again too.  Is this acceptable?

darrenk