Thread: warning: comparison is always false due to limited range of data type

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    20

    Post warning: comparison is always false due to limited range of data type

    hello,
    this is my define declaration
    PHP Code:
     #define CLEANUP_INTERVAL 1000 
    and this is my function body. here getting warning like this
    PHP Code:
     warningcomparison is always false due to limited range of data type 
    how can i over come this problem.
    Code:
    void
    descry(u_char *u, struct pcap_pkthdr *phdr, u_char *packet)
    {
        struct libnet_ipv4_hdr *ip;
        struct libnet_tcp_hdr *tcp;
        struct descry_pack *gp;
        struct tcp_connection *c;
        struct tcp_connection *rc;
        static u_char cleanup = 0;
        struct timeval ts;
    
        rc = NULL;
        c = NULL;
        gp = (struct descry_pack *)u;
    
        /*
         *  In order to keep the trie from growing boundlessly, we need to
         *  periodically expire half open connections.
         */
     
    PHP Code:
      if (cleanup++ > CLEANUP_INTERVAL
    { ts.tv_usec = phdr->ts.tv_usec; ts.tv_sec = phdr->ts.tv_sec; /* expire old connections */ pt_expire(gp, &ts); cleanup = 0; }
    basically using this program i want to scan TCP ip protocal.
    I need your feedback.
    regards
    Nasim

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    1. Just use code tags, not PHP tags.

    2. static u_char cleanup = 0;
    So when do you think an unsigned char will reach 1000 ?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    why dont u use int rather than char, unsigned char can hold up to 255 that it . Look into limit.h. Use int rather than char. That should get rid of your warning.

    ssharish

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  3. C++ FTP class won't work
    By lord mazdak in forum C++ Programming
    Replies: 8
    Last Post: 12-18-2005, 07:57 AM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM