Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > comparison between signed and unsigned

Reply
Thread Tools

comparison between signed and unsigned

 
 
John Buckley
Guest
Posts: n/a
 
      10-23-2003
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



 
Reply With Quote
 
 
 
 
Sheldon Simms
Guest
Posts: n/a
 
      10-23-2003
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

<mIWkb.3815$(E-Mail Removed). net>


 
Reply With Quote
 
 
 
 
Dan Pop
Guest
Posts: n/a
 
      10-24-2003
In <bn8rur$q4r$(E-Mail Removed)> "John Buckley" <(E-Mail Removed)> 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: http://www.velocityreviews.com/forums/(E-Mail Removed)
 
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
Why, warning: comparison between signed and unsigned integer expressions? Lox C Programming 13 05-31-2012 06:11 PM
comparison between signed and unsigned evanevankan2@hushmail.com C Programming 4 07-13-2008 02:50 PM
comparison between signed and unsigned int compcreator@gmail.com C Programming 6 09-21-2007 07:37 PM
comparison between signed and unsigned integer expressions Gary Wessle C++ 4 07-29-2006 05:56 AM
comparison between signed int and unsigned int Alex C Programming 3 04-26-2006 05:20 AM



Advertisments