<p>On Fedora Core 7, I'm writing some code that relies on <code>ARG_MAX</code>.  However, even if I <code>#include &lt;limits.h&gt;</code>, the constant is still not defined.  My investigations show that it's present in <code>&lt;sys/linux/limits.h&gt;</code>, but this is supposed to be portable across Win32/Mac/Linux, so directly including it isn't an option.  What's going on here?</p>

[{'answer_id': 46822, 'author': 'Thomas Kammeyer', 'author_id': 4410, 'author_profile': 'https://Stackoverflow.com/users/4410', 'pm_score': 4, 'selected': True, 'text': '<p>The reason it\'s not in limits.h is that it\'s not a quantity giving the limits of the value range of an integral type based on bit width on the current architecture.  That\'s the role assigned to limits.h by the ISO standard.</p>\n\n<p>The value in which you\'re interested is not hardware-bound in practice and can vary from platform to platform and perhaps system build to system build.</p>\n\n<p>The correct thing to do is to call <code>sysconf</code> and ask it for "ARG_MAX" or "_POSIX_ARG_MAX".  I <em>think</em> that\'s the POSIX-compliant solution anyway.</p>\n\n<p>Acc. to my documentation, you include one or both of unistd.h or limits.h based on what values you\'re requesting.</p>\n\n<p>One other point:  many implementations of the exec family of functions return E2BIG or a similar value if you try to call them with an oversized environment.  This is one of the defined conditions under which exec can actually return.</p>\n'}, {'answer_id': 14834444, 'author': 'Jingguo Yao', 'author_id': 431698, 'author_profile': 'https://Stackoverflow.com/users/431698', 'pm_score': 0, 'selected': False, 'text': '<p>ARG_MAX is defined in /usr/include/linux/limits.h. My linux kernel version is 3.2.0-38.</p>\n'}, {'answer_id': 69613612, 'author': 'TheDudeAbides', 'author_id': 785213, 'author_profile': 'https://Stackoverflow.com/users/785213', 'pm_score': 1, 'selected': False, 'text': '<p>For the edification of future people like myself who find themselves here after a web search for &quot;<a href="https://duckduckgo.com/?q=arg_max+posix" rel="nofollow noreferrer">arg_max posix</a>&quot;, here is a demonstration of the POSIXly-correct method for discerning ARG_MAX on your system that Thomas Kammeyer refers to in his answer:</p>\n<pre class="lang-sh prettyprint-override"><code>cc -x c &lt;(echo \'\n  #include &lt;unistd.h&gt;\n  #include &lt;stdio.h&gt;\n  int main() { printf(&quot;%li\\n&quot;, sysconf(_SC_ARG_MAX)); }\n\')\n</code></pre>\n<p>This uses the <a href="https://www.gnu.org/software/bash/manual/html_node/Process-Substitution.html" rel="nofollow noreferrer">process substitution</a> feature of Bash; put the same lines in a file and run <code>cc thefile.c</code> if you are using some other shell.</p>\n<p>Here\'s the output for macOS 10.14:</p>\n<pre class="lang-sh prettyprint-override"><code>$ ./a.out\n262144\n</code></pre>\n<p>Here\'s the output for a RHEL 7.x system configured for use in an HPC environment:</p>\n<pre class="lang-sh prettyprint-override"><code>$ ./a.out\n4611686018427387903\n\n$ ./a.out | numfmt --to=iec-i  # \'numfmt\' from GNU coreutils\n4.0Ei\n</code></pre>\n<p>For contrast, here is the method prescribed by <a href="https://porkmail.org/era/unix/arg-max.html" rel="nofollow noreferrer">https://porkmail.org/era/unix/arg-max.html</a>, which uses the C preprocessor:</p>\n<pre class="lang-sh prettyprint-override"><code>cpp &lt;&lt;HERE | tail -1\n#include &lt;limits.h&gt;\nARG_MAX\nHERE\n</code></pre>\n<p>This does not work on Linux for reasons still not entirely clear to me—I am not a systems programmer and not conversant in the POSIX or ISO specs—but probably explained above.</p>\n'}]
['https://Stackoverflow.com/questions/46714', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3830/']