Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > comparison is always false due to limited range of data type

Reply
Thread Tools

comparison is always false due to limited range of data type

 
 
Dave
Guest
Posts: n/a
 
      02-26-2005
hello...
I wrote a marco for saturation.
#define clip(x) (char)(x)<0?0(x)>255?255x));
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.


 
Reply With Quote
 
 
 
 
Ben Pfaff
Guest
Posts: n/a
 
      02-26-2005
"Dave" <(E-Mail Removed)> writes:

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


[...]

> 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.
--
"For those who want to translate C to Pascal, it may be that a lobotomy
serves your needs better." --M. Ambuhl

"Here are the steps to create a C-to-Turbo-Pascal translator..." --H. Schildt
 
Reply With Quote
 
 
 
 
Randy Howard
Guest
Posts: n/a
 
      02-26-2005
In article <cvomil$t0m$(E-Mail Removed)>, http://www.velocityreviews.com/forums/(E-Mail Removed)
says...
> hello...
> I wrote a marco for saturation.
> #define clip(x) (char)(x)<0?0(x)>255?255x));
> 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?


--
Randy Howard (2reply remove FOOBAR)
"Making it hard to do stupid things often makes it hard
to do smart ones too." -- Andrew Koenig
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiler warning about comparison always false Nachy C Programming 11 03-14-2012 05:49 PM
warning: comparison is always true due to limited range of data type phil-news-nospam@ipal.net C Programming 6 10-26-2009 11:50 PM
"def nothing=(data) false end" returns 'data' instead of 'false' IƱaki Baz Castillo Ruby 9 02-26-2009 09:38 PM
comparison is always false John Ratliff C++ 8 02-04-2007 10:13 PM
False positive, false intrusion, false alarm Nick Computer Security 3 04-26-2006 07:40 PM



Advertisments