gpt4 book ai didi

linux - _POSIX_* (limits.h) 与 _SC_* (sysconf)

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:41:10 25 4
gpt4 key购买 nike

我刚刚注意到limits.h 中名为“_POSIX_*”的宏(名称上)类似于sysconf 函数的参数。例如,有一个名为“_POSIX_ARG_MAX”的宏,我也可以用“_SC_ARG_MAX”作为参数调用sysconf。当我们完全可以自由使用 limits.h 中的宏时,为什么我们首先需要 sysconf

最佳答案

_POSIX_*值是符合 POSIX 标准的最低要求。它们在所有平台上都具有相同的值(value)。实现支持的特定值可能更高。

来自 man sysconf :

For variables or limits, typically, there is a constant _FOO, maybe defined in <limits.h>, or _POSIX_FOO, maybe defined in <unistd.h>. The constant will not be defined if the limit is unspecified. If the constant is defined, it gives a guaranteed value, and a greater value might actually be supported. If an application wants to take advantage of values which may change between systems, a call to sysconf() can be made. The sysconf() argument will be _SC_FOO.

例如,_POSIX_ARG_MAX是 4096。但是 sysconf(_SC_ARG_MAX)如果系统支持,可能会返回更大的数字。

关于linux - _POSIX_* (limits.h) 与 _SC_* (sysconf),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42652794/

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