gpt4 book ai didi

c - C 中的 "-1L"/"1L"是什么?

转载 作者:太空狗 更新时间:2023-10-29 16:28:16 25 4
gpt4 key购买 nike

C 中的“-1L”、“1L”等是什么意思?

例如,在 ftell 中引用,它说

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

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

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

最佳答案

L 指定数字是 long 类型,所以 -1Llong 设置为负数,1L 是设置为正数的 long

至于为什么ftell不只是返回NULL,是因为NULL是用来做指针的,这里是一个long 被返回。请注意,未使用 0,因为 0ftell 返回的有效值。

捕捉这种情况涉及检查非负值:

long size;
FILE *pFile;

...

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

关于c - C 中的 "-1L"/"1L"是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4115566/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com