Richard Henderson <[EMAIL PROTECTED]> writes: > On Thu, Nov 17, 2005 at 02:01:56PM -0800, Ian Lance Taylor wrote: > > We traditionally do not warn about not using the value returned by a > > function. And I don't see why adding a cast should change that. > > Intuitively, a cast by itself is not a computation. > > In many cases is certainly is -- it's a value transformation; > zero extension, floating-point conversion, etc.
Granted, although in this case the result is being thrown away anyhow. > My opinion is: why is the user asking for a value to be > transformed if they're not going to use the result? It's PR 24900. >From linux/include/asm-i386/apic.h: static __inline void apic_write_atomic(unsigned long reg, unsigned long v) { xchg((volatile unsigned long *)(APIC_BASE+reg), v); } >From system.h: #define xchg(ptr,v) ((__typeof__(*(ptr)))__xchg((unsigned long)(v),(ptr),sizeof(*(ptr)))) So the cast is there becaue __xchg returns a value, and the code wants to get that value into the right type. And presumably in some cases the caller uses the value (or maybe not, I don't know). But in this particular case, the code does not use the value. To me it seems that every step is reasonable: function returns value, macro casts value to appropriate type, caller discards value. What is unreasonable is getting a -Wunused warning in this case. I don't think you should get a warning for not using the return value of a function, at least not under -Wunused. Ian