What is “-1L” in C?

前端 未结 6 1431
梦谈多话
梦谈多话 2020-12-10 11:16

What do \"-1L\", \"1L\" etc. mean in C ?

For example, in ftell reference, it says

... If an error occurs, -1L is returned ...

6条回答
  •  感情败类
    2020-12-10 11:23

    ftell() returns type long int, the L suffix applied to a literal forces its type to long rather than plain int.

    NULL would be wholly incorrect because it is a macro representing a pointer not an integer. Its value, when interpreted and an integer may represent a valid file position, while -1 (or any negative value) cannot.

    For all intents and purposes you can generally simply regard the error return as -1, the L suffix is not critical to correct operation in most cases due to implicit casting rules

提交回复
热议问题