请输入您要查询的百科知识:

 

词条 limits.h
释义

limits.h专门用于检测整型数据数据类型的表达值范围。

limits.h包含内容(包括注释)

/*

* limits.h

* This file has no copyright assigned and is placed in the Public Domain.

* This file is a part of the mingw-runtime package.

* No warranty is given; refer to the file DISCLAIMER within the package.

*

* Functions for manipulating paths and directories (included from io.h)

* plus functions for setting the current drive.

*

* Defines constants for the sizes of integral types.

*

* NOTE: GCC should supply a version of this header and it should be safe to

* use that version instead of this one (maybe safer).

*

*/

#ifndef _LIMITS_H_

#define _LIMITS_H_

/* All the headers include this file. */

#include <_mingw.h>

/*

* File system limits

*

* TODO: NAME_MAX and OPEN_MAX are file system limits or not? Are they the

* same as FILENAME_MAX and FOPEN_MAX from stdio.h?

* NOTE: Apparently the actual size of PATH_MAX is 260, but a space is

* required for the NUL. TODO: Test?

*/

#define PATH_MAX (259)

/*

* Characteristics of the char data type.

*

* TODO: Is MB_LEN_MAX correct?

*/

#define CHAR_BIT 8

#define MB_LEN_MAX 2

#define SCHAR_MIN (-128)

#define SCHAR_MAX 127

#define UCHAR_MAX 255

/* TODO: Is this safe? I think it might just be testing the preprocessor,

* not the compiler itself... */

#if ('\\x80' < 0)

#define CHAR_MIN SCHAR_MIN

#define CHAR_MAX SCHAR_MAX

#else

#define CHAR_MIN 0

#define CHAR_MAX UCHAR_MAX

#endif

/*

* Maximum and minimum values for ints.

*/

#define INT_MAX 2147483647

#define INT_MIN (-INT_MAX-1)

#define UINT_MAX 0xffffffff

/*

* Maximum and minimum values for shorts.

*/

#define SHRT_MAX 32767

#define SHRT_MIN (-SHRT_MAX-1)

#define USHRT_MAX 0xffff

/*

* Maximum and minimum values for longs and unsigned longs.

*

* TODO: This is not correct for Alphas, which have 64 bit longs.

*/

#define LONG_MAX 2147483647L

#define LONG_MIN (-LONG_MAX-1)

#define ULONG_MAX 0xffffffffUL

/*

* The GNU C compiler also allows 'long long int'

*/

#if !defined(__STRICT_ANSI__) && defined(__GNUC__)

#define LONG_LONG_MAX 9223372036854775807LL

#define LONG_LONG_MIN (-LONG_LONG_MAX-1)

#define ULONG_LONG_MAX (2ULL * LONG_LONG_MAX + 1)

/* ISO C9x macro names */

#define LLONG_MAX LONG_LONG_MAX

#define LLONG_MIN LONG_LONG_MIN

#define ULLONG_MAX ULONG_LONG_MAX

/* MSVC compatibility */

#define _I64_MIN LONG_LONG_MIN

#define _I64_MAX LONG_LONG_MAX

#define _UI64_MAX ULONG_LONG_MAX

#endif /* Not Strict ANSI and GNU C compiler */

#endif /* not _LIMITS_H_ */

补充内容

要判断某种特定类型可以容纳的最大值或最小值,一种简便的方法是使用ANSI标准头文件limits.h中的预定义值。该文件包含一些很有用的常量,它们定义了各种类型所能容纳的值,下表列出了这些常量:

----------------------------------------------------------------

常 量 描 述

----------------------------------------------------------------

CHAR_BIT char的位数(bit)

CHAR_MAX char的十进制整数最大值

CHAR_MIN char的十进制整数最小值

MB_LEN_MAX 多字节字符的最大字节(byte)数

INT_MAX int的十进制最大值

INT_MIN int的十进制最小值

LONG_MAX long的十进制最大值

LONG_MIN long的十进制最小值

SCHAR_MAX signedchar的十进制整数最大值

SCHAR_MIN signedchar的十进制整数最小值

SHRT_MIN short的十进制最小值

SHRT_MAX short的十进制最大值

UCHAR_MAX unsignedchar的十进制整数最大值

UINT_MAX unsignedint的十进制最大值

ULONG_MAX unsignedlongint的十进制最大值

USHRT_MAX unsignedshortint的十进制最大值

-----------------------------------------------------------------

对于整数类型,在使用2的补码运算的机器(你将使用的机器几乎都属此类)上,一个有符号类型可以容纳的数字范围为-2到(+2-1),一个无符号类型可以容纳的数字范围为0到(+2-1)。例如,一个16位有符号整数可以容纳的数字范围为--215(即-32768)到(+215-1)(即+32767)。

随便看

 

百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2025/3/4 5:38:11