_POSIX_* (limits.h) 与 _SC_* (sysconf) [英] _POSIX_* (limits.h) vs _SC_* (sysconf)

查看:52
本文介绍了_POSIX_* (limits.h) 与 _SC_* (sysconf)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I just noticed the macros named "_POSIX_*" in limits.h are (namewise) similar to the parameter of sysconf function. For example, there is the macro named "_POSIX_ARG_MAX", and I can also call sysconf with the argument of "_SC_ARG_MAX". Why do we need sysconf in the first place when we're totally free to use the macros in limits.h?

推荐答案

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

The _POSIX_* values are the minimum requirement to be POSIX compliant. They will have the same value on all platforms. The particular value supported by the implementation may be higher.

来自man sysconf:

对于变量或限制,通常有一个常量_FOO,可能定义在,或_POSIX_FOO,可能在 中定义.如果未指定限制,则不会定义常量.如果定义了常量,它会给出一个保证值,并且实际上可能支持更大的值.如果应用程序想要利用可能在系统之间变化的值,可以调用 sysconf().sysconf() 参数将是 _SC_FOO.

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) 如果系统支持它可能会返回更大的数字.

For example, _POSIX_ARG_MAX is 4096. But sysconf(_SC_ARG_MAX) may return a larger number if the system supports it.

这篇关于_POSIX_* (limits.h) 与 _SC_* (sysconf)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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