469,927 Members | 1,766 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

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 4669
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Paul Edwards | last post: by
18 posts views Thread by Timothee Groleau | last post: by
2 posts views Thread by Frederick Gotham | last post: by
8 posts views Thread by John Ratliff | last post: by
14 posts views Thread by Mosfet | last post: by
6 posts views Thread by compcreator | last post: by
5 posts views Thread by evanevankan2 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.