What is “-1L” / “1L” in C?

The L specifies that the number is a long type, so -1L is a long set to negative one, and 1L is a long set to positive one.

As for why ftell doesn’t just return NULL, it’s because NULL is used for pointers, and here a long is returned. Note that 0 isn’t used because 0 is a valid value for ftell to return.

Catching this situation involves checking for a non-negative value:

long size;
FILE *pFile;

...

size = ftell(pFile);
if(size > -1L){
    // size is a valid value
}else{
    // error occurred
}

Leave a Comment