[Numpy-discussion] Toward a numpy build with warning: handling unused variable

Dag Sverre Seljebotn dagss at student.matnat.uio.no
Mon Aug 4 04:26:30 EDT 2008


David Cournapeau wrote:
> On Mon, 2008-08-04 at 01:50 +0200, Stéfan van der Walt wrote:
>> Just to be clear: I meant that I agree with you that we should see
>> NumPy related warnings that aren't smothered in bogus messages.  Is
>> there no way to do this without compiler-specific hacks?
> 
> Yes, there is, but it is more error prone (because then you are hiding
> the warning instead of saying it is unused with a safeguard against any
> use). I would not call this an hack, because __attribute__ is a well
> known, well used gcc mechanism. For people not using gcc, it would not
> change anything.
> 
> Maybe there are another more portable methods I am not aware of, though.
> 
> cheers,

How about this:

#define UNUSED(x) (x=x)

void func(int a, int b, int c) {
   UNUSED(a); UNUSED(b);
   ...
}

Alternatively,

#define UNUSED(x) ((void)x)

also seems to stop the warning. I only tested this on 4.2.3, YMMV.

-- 
Dag Sverre



More information about the NumPy-Discussion mailing list