comparison between signed and unsigned

Discussion in 'C Programming' started by John Buckley, Oct 23, 2003.

  1. John Buckley

    John Buckley Guest

    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
     
    John Buckley, Oct 23, 2003
    #1
    1. Advertising

  2. 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$>
     
    Sheldon Simms, Oct 23, 2003
    #2
    1. Advertising

  3. John Buckley

    Dan Pop Guest

    In <bn8rur$q4r$> "John Buckley" <> 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:
     
    Dan Pop, Oct 24, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex
    Replies:
    3
    Views:
    673
    Michael Mair
    Apr 26, 2006
  2. Gary Wessle
    Replies:
    4
    Views:
    673
    Ian Collins
    Jul 29, 2006
  3. Replies:
    6
    Views:
    403
    Army1987
    Sep 21, 2007
  4. Replies:
    4
    Views:
    411
  5. Lox
    Replies:
    13
    Views:
    2,437
    Joe Pfeiffer
    May 31, 2012
Loading...

Share This Page