I could see in the mmap man page the return value during error condition is (void *)-1.
how c compiler will treat (void *) before a constant, here -1.
is the following code snippet is the correct way of checking the error value of mmap?
int *p;
p = (int *)mmap();
if(p == -1)
printf("error \n");
do we need to use the following error condition check.
if(*p == -1)
printf("error \n");
Check literally with
(void *)-1or useMAP_FAILEDmacro which is defined to(void *)-1.if(*p == -1)is incorrect as you can not dereference the pointer unless you ensure the validity of the pointer. Otherwise the behaviour of the program is undefined.