什么是" -1L"用C? [英] What is "-1L" in C?

查看:172
本文介绍了什么是" -1L"用C?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是-1L,1L等意思?

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

例如,在 FTELL 参考,它说:

...如果发生错误,则返回-1L ...

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

这是什么意思?什么是1L的类型?

What does this mean ? What is the type of "1L" ?

为什么不返回NULL,如果发生错误?

Why not return NULL, if error occurs ?

推荐答案

指定号码是类型,所以 -1L 设置为负一和 1L 设置为积极的。

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.

至于为什么 FTELL 不只是返回 NULL ,这是因为 NULL 用于指针,这里被返回。需要注意的是 0 未使用,因为 0 FTELL 返回。

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
}

这篇关于什么是" -1L"用C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆