comparison is always false due to limited range of data type

D

Dave

hello...
I wrote a marco for saturation.
#define clip(x) (char)(x)<0?0:((x)>255?255:(x));
and use this marco in the program like this...
char tmp=(char)clip((unsigned_int_16)(tmp1+tmp2));

which unsigned_int_16 will cast the (tmp1+tmp2) to 16 bit
unsigned int.

Each time when I compile this program, the gcc warning me the
"comparison is always false due to limited range of data type"

Where leads this problem?
Please tell me! Thanx~~~

Dave.
 
B

Ben Pfaff

Dave said:
I wrote a marco for saturation.
#define clip(x) (char)(x)<0?0:((x)>255?255:(x));
[...]

Each time when I compile this program, the gcc warning me the
"comparison is always false due to limited range of data type"

Presumably `char' is unsigned, so the comparison (char)(x) < 0
is always false.

By the way, you seem to be over-fond of casts. You might want to
consider which casts are actually necessary and get rid of the
others.
 
R

Randy Howard

hello...
I wrote a marco for saturation.
#define clip(x) (char)(x)<0?0:((x)>255?255:(x));
and use this marco in the program like this...
char tmp=(char)clip((unsigned_int_16)(tmp1+tmp2));

which unsigned_int_16 will cast the (tmp1+tmp2) to 16 bit
unsigned int.

Each time when I compile this program, the gcc warning me the
"comparison is always false due to limited range of data type"

What do you think x < 0 does on an unsigned data type?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top