[Warning] comparison between pointer and integer

This is a discussion on [Warning] comparison between pointer and integer within the C Programming forums, part of the General Programming Boards category; Hi guys, quick one, think it should be easy for you c cracks. This line: Code: else if((lines%3)!=NULL) Results in ...

  1. #1
    1ST » R. vd Kooij
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    154

    [Warning] comparison between pointer and integer

    Hi guys, quick one, think it should be easy for you c cracks.

    This line:
    Code:
          else if((lines%3)!=NULL)
    Results in this warning:
    [Warning] comparison between pointer and integer

    lines is defined as an integer and is 3 in this case.

    What need I do to avoid getting this warning please?

    Thanks in advance,

    René
    http://www.f1rstracing.nl/
    OS: Windows XP
    Compiler: Dev-C++

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    e.g.
    Code:
          else if( lines%3 )
    Kurt

  3. #3
    1ST » R. vd Kooij
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    154
    Quote Originally Posted by ZuK
    e.g.
    Code:
          else if( lines%3 )
    Kurt
    Ah! NULL != 0 right?

    Damn, knew it was simple

    Thanks
    http://www.f1rstracing.nl/
    OS: Windows XP
    Compiler: Dev-C++

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >What need I do to avoid getting this warning please?
    Simple, don't use NULL except in pointer context. If you want to compare against 0 then use 0. If you want to compare against '\0' then use '\0'. If you want to test for a null pointer then use NULL.

    The reason you're getting the error is because NULL is defined as 0 with a pointer type, most likely like this:
    Code:
    #define NULL ((void*)0)
    The result of a boolean expression, lines%3, has an integer type.
    My best code is written with the delete key.

  5. #5
    1ST » R. vd Kooij
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    154
    Good explanation, thanks a lot.
    *feels dumb* though
    http://www.f1rstracing.nl/
    OS: Windows XP
    Compiler: Dev-C++

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >*feels dumb* though
    If you knew the confusion that NULL has caused in the past then you would feel very smart about understanding the problem so quickly.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-20-2009, 11:37 PM
  3. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 05:55 PM
  4. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  5. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21