_POSIX_* (limits.h) vs _SC_* (sysconf)

佐手、 提交于 2021-01-28 11:34:09

问题


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?


回答1:


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.

From 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.

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



来源:https://stackoverflow.com/questions/42652794/posix-limits-h-vs-sc-sysconf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!