gpt4 book ai didi

c - posix_memalign() 是否在失败时将指针设置为 NULL?

转载 作者:太空宇宙 更新时间:2023-11-04 02:46:23 26 4
gpt4 key购买 nike

int posix_memalign(void **memptr, size_t alignment, size_t size);

分配 size 字节,按 alignment 对齐。成功返回 0,失败返回 errno。

*memptr 是否在失败时设置为 0?

最佳答案

可能会,但不能保证。

参见 the specification它只是说:

Upon successful completion, posix_memalign() shall return zero; otherwise, an error number shall be returned to indicate the error.

它没有说明发生错误时 *memptr 会发生什么,所以我的解读是它的状态未定义。显然,两个最理智的行为是 0,或者保持原样,但你不能依赖它。

关于c - posix_memalign() 是否在失败时将指针设置为 NULL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26833153/

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