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

comparison between signed and unsigned

Hello!

In my program I need to compare a long variable with a size_t variable. The
long variable's value is guaranteed to be positive since it's initialised by
a function returning a positive value (or -1L when an error occurs, which I
check for). When I compare these variables with >, I get the warning
"comparison between signed and unsigned". Given that the long variable is
guaranteed to hold a positive value, can I ignore this diagnostic or should
I deal with it in some way?

BTW, I'm having endless trouble getting the hang of C. I can't quite
understand it because I tend to grasp languages pretty quickly. How long
does it take for C to truly 'click'?

---
JB

Nov 13 '05 #1
2 4919
On Thu, 23 Oct 2003 16:26:10 +0100, John Buckley wrote:
Hello!

In my program I need to compare a long variable with a size_t variable. The
long variable's value is guaranteed to be positive since it's initialised by
a function returning a positive value (or -1L when an error occurs, which I
check for). When I compare these variables with >, I get the warning
"comparison between signed and unsigned". Given that the long variable is
guaranteed to hold a positive value, can I ignore this diagnostic or should
I deal with it in some way?


There was a thread recently talking about this. The message ID of the
first post was

<mI*****************@newsread3.news.pas.earthlink. net>
Nov 13 '05 #2
In <bn**********@newsg2.svr.pol.co.uk> "John Buckley" <us**@example.net> writes:
In my program I need to compare a long variable with a size_t variable. The
long variable's value is guaranteed to be positive since it's initialised by
a function returning a positive value (or -1L when an error occurs, which I
check for). When I compare these variables with >, I get the warning
"comparison between signed and unsigned". Given that the long variable is
guaranteed to hold a positive value, can I ignore this diagnostic or should
I deal with it in some way?
The best thing to do, if you trust your C skills, is to disable (or not
enable) this warning. Most of the time (or all the time if you know what
you're doing) it is merely a source of noise. gcc -Wall, for example,
does not enable such warnings, leaving them for the masochists who also
use -W.
BTW, I'm having endless trouble getting the hang of C. I can't quite
understand it because I tend to grasp languages pretty quickly. How long
does it take for C to truly 'click'?


It depends on how much time you spend trying to understand the language,
rather than playing with it. After reading K&R2 and the c.l.c FAQ, you
should have a fairly clear idea about the language, including most of the
darker spots.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #3

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

Similar topics

0
by: g | last post by:
Hi all. Maybe this question has been asked many times before, but I was not able to find any pointer. I apologize in advance, for it refers to a particular standard library implementation (GNU...
1
by: Paul Edwards | last post by:
I have the following C program: #include <stdio.h> int main(void) { unsigned short x = 32768, y=16384; if (x > y) {
3
by: Alex | last post by:
I have a problem about the comparison between signed and unsigned integer. See the following code: int foo() { int i; unsigned int j; if (i < j) {
18
by: Timothee Groleau | last post by:
Hi all, When should I be worried about doing a comparison of signed vs unsigned ints? Could someone give me a example where such a comparison would lead to unwanted results? Thanks, Tim.
2
by: Frederick Gotham | last post by:
I just want to clarify my understanding of arithmetic and comparison between two different integer types. Phase (1): Integer Promotion ---------- All of the following types always get...
4
by: Gary Wessle | last post by:
Hi I am writing a code to open a space delimited data file, return the number of rows and columns, as well as return the nth column where n is user define number. I put all the cells in 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...
14
by: Mosfet | last post by:
Hi, what is the most efficient way of doing a case insensitive comparison ? I am trying to write a universal String class and I am stuck with the case insensitive part : TCHAR is a char in...
6
by: compcreator | last post by:
I have tried the following program. The problem is it is printing False I checked values for a and b but there is something wrong with the comparison. I thing it might be because of signed and...
5
by: evanevankan2 | last post by:
I have a question about the warning 'comparison between signed and unsigned' I get from my code. It comes from the conditional in the outer for loop. I understand the warning, but I'm not sure...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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.