1.11M Members

Boundary condition with memcmp on Linux

 
0
 

I ran same code linux and HP platform And the result stored was different.
I found that the boundar for comparison is 255.
It can be more undersstood from the below code.

#include <stdio.h>

int main()
{
    FILE *fp=fopen("linux2.txt","wb");
    int a = 100;
    int c=0;
    int i=0;
    for (i=0; i <= 32767; i++)
       {
          c = memcmp(&a,&i,sizeof(int));
                if ( c >0 )
                        fprintf (fp,"Value is -1 when i = %d\n",i);
             }
    fclose(fp);
    return 0;
}

The answer stored in Linux and HP was different.
In HP the text file created had only first 99 numbers but on linux it was 0-99 then 256-355 and so on.

Anyone have any idea about limitation of memcmp function.

 
0
 

So am I to assume that you completely ignored the replies from your other thread that asks essentially the same question?

 
0
 

Deceptikon, By the time i got answer from 2nd thread i had already posted this....
Anyways Thanks for your answer..

Question Answered as of 1 Year Ago by deceptikon
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: