On 05/01/11 09:03, Jim Meyering wrote: > PÃdraig Brady wrote: > ... >>>> Perhaps this might work? >>>> >>>> static inline void _ignore (int i) { (void) i; } >>>> #define ignore(x) _ignore ((int)x) >>> >>> I don't think so, it will produce warnings about cast from pointer to >>> integer if the function (foo() in my example) returns a pointer. >> >> Ah right, there would be a warning when the pointer >> size is different to the int. So this would be better: >> >> #include <stdint.h> >> static inline void _ignore (intptr_t p) { (void) p; } >> #define ignore(x) _ignore ((intptr_t)x) > > Nice. > That works for me, as a plug-in replacement for gnulib's ignore-value.h: > > #include <stdint.h> > static inline void _ignore_value (intptr_t p) { (void) p; } > #define ignore_value(x) _ignore_value ((intptr_t) x) > > /* ignore_value now works for both scalars and pointers, so deprecate. */ > static inline void __attribute__((__deprecated__)) > ignore_ptr (void* p) { (void) p; } /* deprecated: use ignore_value */ > > i.e., with the above (and a few s/ignore_ptr/ignore_value/), > coreutils still compiles warning-free. > > I opted to stick with ignore_value, since the name "ignore" is > probably too common to usurp like that. For example, while it > doesn't conflict per se, sort.c does have both a local variable and > a struct member named "ignore". > > The only drawback (probably acceptable) is that > it adds a dependency on <stdint.h>. > >> But that still doesn't work for aggregate types. > > That's ok. Those are far less common. > > ------------------------------------------------ > Here's the gnulib patch: > > diff --git a/lib/ignore-value.h b/lib/ignore-value.h > index 04d6520..7e5ae3a 100644 > --- a/lib/ignore-value.h > +++ b/lib/ignore-value.h > @@ -35,8 +35,14 @@ > #ifndef _GL_IGNORE_VALUE_H > # define _GL_IGNORE_VALUE_H > > -static inline void ignore_value (int i) { (void) i; } > -static inline void ignore_ptr (void* p) { (void) p; } > +#include <stdint.h> > +static inline void _ignore_value (intptr_t p) { (void) p; } > +#define ignore_value(x) _ignore_value ((intptr_t) x) > + > +/* ignore_value now works for both scalars and pointers, so deprecate. */ > +static inline void __attribute__((__deprecated__)) > +ignore_ptr (void* p) { (void) p; } /* deprecated: use ignore_value */ > + > /* FIXME: what about aggregate types? */ > > #endif > diff --git a/modules/ignore-value b/modules/ignore-value > index 8d48863..aeda194 100644 > --- a/modules/ignore-value > +++ b/modules/ignore-value > @@ -5,6 +5,7 @@ Files: > lib/ignore-value.h > > Depends-on: > +stdint > > configure.ac: > AC_REQUIRE([AC_C_INLINE]) > Cool, thanks for doing that. It probably needs this too: #ifndef __attribute__ /* The __attribute__((__deprecated__) feature is available in gcc versions 3.1 and later. */ # if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 1) # define __attribute__(Spec) /* empty */ # endif #endif -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html