(void *)-1的含义 [英] significance of (void*) -1
问题描述
我正在查看sbrk
系统调用的文档,发现此:
I was looking at the documentation of sbrk
system call and found this:
成功后,
sbrk()
返回上一个程序中断. (如果增加了中断,则此值是指向新分配的内存的起点的指针).出现错误时,将返回(void *) -1
,并将errno
设置为ENOMEM
.
On success,
sbrk()
returns the previous program break. (If the break was increased, then this value is a pointer to the start of the newly allocated memory). On error,(void *) -1
is returned, anderrno
is set toENOMEM
.
现在
-
(void *) -1
的意义是什么?
它指向的确切内存地址是什么? (如果有的话)
What is the exact memory address it points to? (if it does at all)
如何保证(void *) -1
不是有效地址
可以由sbrk()
成功返回吗?
How is it guaranteed that (void *) -1
is not a valid address
that can be returned by sbrk()
on success?
推荐答案
(void *) -1 == (size_t) -1
在32位计算机上为0xFFFFFFFF
,在64位计算机上为0xFFFFFFFFFFFFFFFF
,该无效地址应该大于任何其他地址.
It's 0xFFFFFFFF
on 32 bit machine and 0xFFFFFFFFFFFFFFFF
on 64 bit machine, an invalid address that is supposed to be bigger than any other address.
这篇关于(void *)-1的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!