OpenBSD manual page server

Manual Page Search Parameters

LIMITS(3) Library Functions Manual LIMITS(3)

limitsstandard limits

#include <limits.h>

The <limits.h> header defines various compile-time and runtime limits. These can be grouped into three categories:

  1. Compile-time limits defined in a header file.
  2. Runtime system limits that are not associated with a file or directory; see sysconf(3).
  3. Runtime limits that are associated with a file or directory; see pathconf(2).

The <limits.h> header has been standardized by at least three entities.

The limits defined by the ISO/IEC 9899:1999 (“ISO C99”) standard are all compile-time limits. The numerical (integer) limits are:

Constant Type Minimum value
char 8
signed char 127
signed char -127
unsigned char 255

int 32767
int -32767
unsigned int 65535

short -32767
short 32767
unsigned short 65535

long int 2147483647
long int -2147483647
unsigned long int 4294967295

long long int 9223372036854775807
long long int -9223372036854775807
unsigned long long int 18446744073709551615

- 1

All listed limits may vary across machines and operating systems. The standard guarantees only that the implementation-defined values are equal or greater in absolute value to those shown. The values permit a system with 16-bit integers using one's complement arithmetic.

Depending whether the system defines char as signed or unsigned, the maximum and minimum values are:

Constant Type Minimum value
char either SCHAR_MAX or UCHAR_MAX
char either SCHAR_MIN or 0

The two special cases, CHAR_BIT and MB_LEN_MAX, define the number of bits in char and the maximum number of bytes in a multibyte character constant, respectively.

The POSIX.1 standard specifies numerous limits related to the operating system. For each limit, a separate constant prefixed with “_POSIX_” defines the lowest value that the limit is allowed to have on any POSIX compliant system. For instance, _POSIX_OPEN_MAX defines the minimum upper bound permitted by POSIX for the number of files that a single process may have open at any time. This ensures that a portable program can safely reach these limits without prior knowledge about the actual limits used in a particular system.

As the limits are not necessary invariant, pathconf(2) and sysconf(3) should be used to determine the actual value of a limit at runtime. The manual pages of these two functions also contain a more detailed description of the limits available in NetBSD.

Also the X/Open System Interface Extension (XSI) specifies few limits. In NetBSD these are limited to LONG_BIT (the number of bits in long), WORD_BIT (the number of bits in a “word”), and few limits related to float and double.

getconf(1), pathconf(2), sysconf(3), types(3), unistd(3)

Richard W. Stevens and Stephen A. Rago, Advanced Programming in the UNIX Environment, Addison-Wesley, Second Edition, 2005.

August 9, 2011 NetBSD-7.0.1