On Wed, Nov 08, 2006 at 11:07:15PM +0100, Ulf Lamping wrote:

> Joerg Mayer wrote:
> > gtkvumeter.c:946: warning: comparison of unsigned expression < 0 is
> > always false
> >   
> CLAMP is called with three variables of type GtkVUMeterScaling
> > gtkvumeter.c:1144: warning: comparison of unsigned expression < 0 is
> > always false
> >   
> CLAMP is called with three variables of type GtkVUMeterPeakFalloff
> 
> Both types are "typedef enum" so I don't understand these warnings.

Since an enum defines the first value 0 and the next 1, look at what the 
CLAMP macro from Glib expands into:

Definition:
#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? 
(low) : (x)))

Our use:
vumeter->scaling = CLAMP (scaling, GTK_VUMETER_SCALING_LINEAR, 
GTK_VUMETER_SCALING_LOG);

Which turns into:
((scaling) > (1)) ? (1) : (((scaling) < (0)) ? (0) : (scaling)))

An enum is by default "unsigned" since it starts at 0, the macro's check 
of < 0 can never be true.

One way that you can fix the warning is by manually assigning numbers to 
the enumerated values in gtkvumeter.h:

typedef enum {
    GTK_VUMETER_SCALING_LINEAR=1,
    GTK_VUMETER_SCALING_LOG=2
} GtkVUMeterScaling;

typedef enum {
    GTK_VUMETER_PEAK_FALLOFF_SLOW=1,
    GTK_VUMETER_PEAK_FALLOFF_MEDIUM=2,
    GTK_VUMETER_PEAK_FALLOFF_FAST=3,
    GTK_VUMETER_PEAK_FALLOFF_USER=4
} GtkVUMeterPeakFalloff;

It looks like CLAMP is being used here to just check if the value is 
equal to one or the other (it can't be in between since the parameter x 
is the same enum).


Steve
_______________________________________________
Wireshark-dev mailing list
Wireshark-dev@wireshark.org
http://www.wireshark.org/mailman/listinfo/wireshark-dev

Reply via email to