473,387 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

comparison is always false due to limited range of data type

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.
Nov 14 '05 #1
2 11957
"Dave" <wc***@cs.ccu.edu.tw> writes:
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.
--
"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
Nov 14 '05 #2
In article <cv**********@reader.ccu.edu.tw>, wc***@cs.ccu.edu.tw
says...
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?
--
Randy Howard (2reply remove FOOBAR)
"Making it hard to do stupid things often makes it hard
to do smart ones too." -- Andrew Koenig
Nov 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Simon Burton | last post by:
In today's experiment, I was wondering if I could make the comparison operators (<,<=,>=,>) work on classes (types) according to inheritance. The idea is, for example, classes lower in the class...
133
by: jonathan | last post by:
hey all, I realize that this question might pop up from time to time, but I haven't seen it a while and things might of changed, so - Right now (July 2004) how does mysql stand up in...
0
by: Brian Young | last post by:
Hi all. I'm using the Property Grid control in a control to manage a windows service we have developed here. The windows service runs a set of other jobs that need to be managed. The control...
37
by: spam.noam | last post by:
Hello, Guido has decided, in python-dev, that in Py3K the id-based order comparisons will be dropped. This means that, for example, "{} < " will raise a TypeError instead of the current...
43
by: michael.f.ellis | last post by:
The following script puzzles me. It creates two nested lists that compare identically. After identical element assignments, the lists are different. In one case, a single element is replaced. In...
4
by: Mike Duffy | last post by:
I just recently realized that the comparison operator "is" actually works for comparing numeric values. Now, I know that its intended use is for testing object identity, but I have used it for a...
8
by: John Ratliff | last post by:
"comparison is always false due to limited range of data type" I get this warning with g++ when I compile some code and I'm not quite sure I understand it. I have a small file that I've read...
1
by: Lars B | last post by:
Hey guys, I have written a C++ program that passes data from a file to an FPGA board and back again using software and DMA buffers. In my program I need to compare the size of a given file against...
2
by: a1drich | last post by:
smartCryptor.cpp: In function `void Char2Hex(unsigned char, char*)': smartCryptor.cpp:188: warning: comparison is always true due to limited range of data type void Char2Hex(unsigned char...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.