473,378 Members | 1,312 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,378 software developers and data experts.

What could the compiler be possibly complaining about

Are there any compiler groups.
Though I try it in this language forum
I got the following message for the following line in a c file

if (logic_value_change == p_variable_info->vc_reason &&
p_variable_info->p_value->logic_value <4 &&
p_variable_info->p_value->logic_value>=0)

The message is
.../star186559.c: In function `func_var':
.../star186559.c:320: warning: comparison is always true due to limited
range of data type

comparison is always true ????

The data type fpr logic_value is a unsigned char
-Parag
Mar 6 '08 #1
4 1113
pa********@hotmail.com said:
Are there any compiler groups.
Yes, but you don't need one for this question, which is about the C
language.
Though I try it in this language forum
I got the following message for the following line in a c file

if (logic_value_change == p_variable_info->vc_reason &&
p_variable_info->p_value->logic_value <4 &&
p_variable_info->p_value->logic_value>=0)

The message is
../star186559.c: In function `func_var':
../star186559.c:320: warning: comparison is always true due to limited
range of data type

comparison is always true ????
Yes.
The data type fpr logic_value is a unsigned char
An unsigned char cannot hold negative values. It can only hold values in
the range 0 to UCHAR_MAX, which is guaranteed to be a positive integer
value that is at least 255 (but is higher on some systems).

The comparison you have is: p_variable_info->p_value->logic_value>=0

Now, *any* unsigned char value *must* have a value greater than or equal to
0, by definition. Therefore, the comparison >= 0 will always yield true
for an unsigned char, which is exactly what the compiler is (correctly)
telling you.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Mar 6 '08 #2
pa********@hotmail.com wrote:
Are there any compiler groups.
Though I try it in this language forum
I got the following message for the following line in a c file

if (logic_value_change == p_variable_info->vc_reason &&
p_variable_info->p_value->logic_value <4 &&
p_variable_info->p_value->logic_value>=0)
The message is
.../star186559.c: In function `func_var':
.../star186559.c:320: warning: comparison is always true due to limited
range of data type
comparison is always true ????
The data type fpr logic_value is a unsigned char
The comparison
p_variable_info->p_value->logic_value>=0)
is obviously always true if logic_value is an unsigned char.
An unsigned char cannot be less than zero.
Mar 6 '08 #3
pa********@hotmail.com wrote:
Are there any compiler groups.
Though I try it in this language forum
I got the following message for the following line in a c file

if (logic_value_change == p_variable_info->vc_reason &&
p_variable_info->p_value->logic_value <4 &&
p_variable_info->p_value->logic_value>=0)

The message is
../star186559.c: In function `func_var':
../star186559.c:320: warning: comparison is always true due to limited
range of data type

comparison is always true ????

The data type for logic_value is a unsigned char
-Parag
That warning sometimes comes up when you compare variables of different
sizes. To really know what you need to do differently, I'd need the
types of all the other variables you are comparing as well.

To illustrate what is happening here, consider an unsigned char.
Because it is only eight bytes long and can store values no larger than
255, if you write something like:

int function {
char a = 255;
if (a < 256) return 1;
};

The comparison will always be true and the function will always return 1.

As a point of practice, it's always a good idea to put parentheses
around the parts of a condition, eg:

if ( (logic_value_change == p_variable_info->vc_reason) &&
(p_variable_info->p_value->logic_value < 4) &&
(p_variable_info->p_value->logic_value >= 0) )

However, conveniently, the precedence of ==, <, and >= are all greater
than that of &&, so that shouldn't be your issue. -trumps all of
those. I'm guessing that the issue is as simple as logic_value_change
and vc_reason having silly types.

--
--Falcon Kirtaran
Mar 7 '08 #4
Falcon Kirtaran wrote:
pa********@hotmail.com wrote:
>Are there any compiler groups.
Though I try it in this language forum
I got the following message for the following line in a c file

if (logic_value_change == p_variable_info->vc_reason &&
p_variable_info->p_value->logic_value <4 &&
p_variable_info->p_value->logic_value>=0)

The message is
../star186559.c: In function `func_var':
../star186559.c:320: warning: comparison is always true due to limited
range of data type

comparison is always true ????

The data type for logic_value is a unsigned char
-Parag

That warning sometimes comes up when you compare variables of different
sizes. To really know what you need to do differently, I'd need the
types of all the other variables you are comparing as well.

To illustrate what is happening here, consider an unsigned char. Because
it is only eight bytes long and can store values no larger than 255, if
you write something like:

int function {
char a = 255;
if (a < 256) return 1;
};

The comparison will always be true and the function will always return 1.

As a point of practice, it's always a good idea to put parentheses
around the parts of a condition, eg:

if ( (logic_value_change == p_variable_info->vc_reason) &&
(p_variable_info->p_value->logic_value < 4) &&
(p_variable_info->p_value->logic_value >= 0) )

However, conveniently, the precedence of ==, <, and >= are all greater
than that of &&, so that shouldn't be your issue. -trumps all of
those. I'm guessing that the issue is as simple as logic_value_change
and vc_reason having silly types.

--
--Falcon Kirtaran
Bah. Clearly, I am a fool. Your problem is "logic_value>=0" because
unsigned types can't contain negative numbers.
Mar 9 '08 #5

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

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
6
by: Peter Ross | last post by:
I get a link error when I try and create a module of the following very simple managed C++ code. I can't imagine a more minimum piece of code, so I imagine that this is some sort of compiler bug....
4
by: huguogang | last post by:
Just curious, any one know what the 3 part parameter "class CString filename" would mean. The code: int TestFunc(class CString filename) { fopen(filename, "w"); } Compile using Visaul C++,...
17
by: Grizlyk | last post by:
Hello. What can be optimised in C++ code and how i can garantee stable behaviour below 1. Are expression "auto volatile" can deny removing as "unused temporary" like this: auto volatile...
15
by: robert maas, see http://tinyurl.com/uh3t | last post by:
Here's the source: #include <stdio.h> #include <errno.h> main () { char* str = "9999999999"; long long int llin; char* endptr; /* Set by strtoll */ int nch; errno = 0; llin = strtoll(str,...
30
by: albert.neu | last post by:
Hello! What is a good compiler to use? (for MS Windows, for Linux) Any recommendations?? What's the point of having a C99 standard, if different compilers still produce differing results? ...
49
by: valentin tihomirov | last post by:
fDeleted = false; uint jobId; foreach (Struct struct in structures) { if (struct.type == JOB) { jobId = struct.id; if (struct.dataType == STATUS) fDeteted = (struct.data & STATUS_DELETED) !=...
38
by: larry | last post by:
I am looking at some code which process an uploaded file and it has loops like: for(;;){ // for([two semicolons){ what is the function of the two semicolons? loop until break? I've...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: 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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.