CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2009
    Posts
    40

    Red face warning: comparison between

    [ ]$ g++ -Wall -g hashphonedirectory.cpp -o hashphonedirectory
    hashphonedirectory.cpp: In member function âint File::Hash(char*)â:
    hashphonedirectory.cpp:16: warning: comparison between signed and unsigned integer expressions
    hashphonedirectory.cpp: At global scope:
    hashphonedirectory.cpp:214: warning: ISO C++ forbids declaration of âmainâ with no type
    -------------------------------------------------------
    CODE ERROR

    int File::Hash(char *
    {
    for(xorin = 0; strlen( >= unit; s+= unit) //xoring
    xorin ^= * (unsigned *) s;

    if(strlen (s) ) {
    strcpy ((char *)&remainder, s);//character
    xorin ^= remainder;

    }
    return (xorin % tableSize) * bucketSize * recordLen;

    }

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: warning: comparison between

    Code:
    int File::Hash(char *
    {
    Code:
    for(xorin = 0; strlen( >= unit; s+= unit) //xoring
    You are missing something here...

    btw... never use something like strlen in a for loop, because it will calculate the length EVERY iteration. So if you loop it 100 times it will calculate the length 100 times...
    Last edited by Skizmo; May 16th, 2009 at 09:28 AM.

  3. #3
    Join Date
    Mar 2009
    Posts
    40

    Unhappy Re: warning: comparison between

    I miss the (s)

    but what do you suggest instead of strlen?

  4. #4
    Join Date
    Jan 2006
    Location
    Belo Horizonte, Brazil
    Posts
    405

    Re: warning: comparison between

    Quote Originally Posted by olove View Post
    I miss the (s)
    but what do you suggest instead of strlen?
    You can use strlen. You just shouldn't use it inside the loop condition. Calculate the string length before the for statement and then use the calculated value.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured