(void *)-1的含义 [英] significance of (void*) -1

查看:512
本文介绍了(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, and errno is set to ENOMEM.

现在

  1. (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屋!

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