QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1740|回复: 6

现在知道为什么操作系统的数值大小范围不同了

[复制链接]
发表于 2002-11-26 10:48:40 | 显示全部楼层 |阅读模式
记得以前学习和给别人讲课的时候,总搞不明白各种类型的整数的范围为什么不相同。原来在操作系统的源代码有定义,MINIX在limit.h里,呵呵。
发表于 2002-11-26 10:59:20 | 显示全部楼层
不一定吧,那我用tc编出来的程序,在window下跑,int长度变成4个,不乱套了吗,我觉得和编译器有关
回复

使用道具 举报

发表于 2002-11-26 11:08:49 | 显示全部楼层
对!应该是和编译器有关.我想
回复

使用道具 举报

发表于 2002-11-26 20:31:13 | 显示全部楼层
把那段代码写出来大家看一下究竟是怎么回事吧。
回复

使用道具 举报

 楼主| 发表于 2002-11-27 11:39:25 | 显示全部楼层
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                                include/limits.h                  
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

00100        /* The <limits.h> header defines some basic sizes, both of the language types
00101         * (e.g., the number of bits in an integer), and of the operating system (e.g.
00102         * the number of characters in a file name.
00103         */
00104       
00105        #ifndef _LIMITS_H
00106        #define _LIMITS_H
00107       
00108        /* Definitions about chars (8 bits in MINIX, and signed). */
00109        #define CHAR_BIT           8    /* # bits in a char */
00110        #define CHAR_MIN        -128    /* minimum value of a char */
00111        #define CHAR_MAX         127    /* maximum value of a char */
00112        #define SCHAR_MIN       -128    /* minimum value of a signed char */
00113        #define SCHAR_MAX        127    /* maximum value of a signed char */
00114        #define UCHAR_MAX        255    /* maximum value of an unsigned char */
00115        #define MB_LEN_MAX         1    /* maximum length of a multibyte char */
00116       
00117        /* Definitions about shorts (16 bits in MINIX). */
00118        #define SHRT_MIN  (-32767-1)    /* minimum value of a short */
00119        #define SHRT_MAX       32767    /* maximum value of a short */
00120        #define USHRT_MAX     0xFFFF    /* maximum value of unsigned short */
00121       
00122        /* _EM_WSIZE is a compiler-generated symbol giving the word size in bytes. */
00123        #if _EM_WSIZE == 2
00124        #define INT_MIN   (-32767-1)    /* minimum value of a 16-bit int */
00125        #define INT_MAX        32767    /* maximum value of a 16-bit int */
00126        #define UINT_MAX      0xFFFF    /* maximum value of an unsigned 16-bit int */
00127        #endif
00128       
00129        #if _EM_WSIZE == 4
00130        #define INT_MIN (-2147483647-1) /* minimum value of a 32-bit int */
00131        #define INT_MAX   2147483647    /* maximum value of a 32-bit int */
00132        #define UINT_MAX  0xFFFFFFFF    /* maximum value of an unsigned 32-bit int */
00133        #endif
00134       
00135        /*Definitions about longs (32 bits in MINIX). */
00136        #define LONG_MIN (-2147483647L-1)/* minimum value of a long */
00137        #define LONG_MAX  2147483647L   /* maximum value of a long */
00138        #define ULONG_MAX 0xFFFFFFFFL   /* maximum value of an unsigned long */
00139       
00140        /* Minimum sizes required by the POSIX P1003.1 standard (Table 2-3). */
00141        #ifdef _POSIX_SOURCE            /* these are only visible for POSIX */
00142        #define _POSIX_ARG_MAX    4096  /* exec() may have 4K worth of args */
00143        #define _POSIX_CHILD_MAX     6  /* a process may have 6 children */
00144        #define _POSIX_LINK_MAX      8  /* a file may have 8 links */
00145        #define _POSIX_MAX_CANON   255  /* size of the canonical input queue */
00146        #define _POSIX_MAX_INPUT   255  /* you can type 255 chars ahead */
00147        #define _POSIX_NAME_MAX     14  /* a file name may have 14 chars */
00148        #define _POSIX_NGROUPS_MAX   0  /* supplementary group IDs are optional */
00149        #define _POSIX_OPEN_MAX     16  /* a process may have 16 files open */
00150        #define _POSIX_PATH_MAX    255  /* a pathname may contain 255 chars */
00151        #define _POSIX_PIPE_BUF    512  /* pipes writes of 512 bytes must be atomic */
00152        #define _POSIX_STREAM_MAX    8  /* at least 8 FILEs can be open at once */
00153        #define _POSIX_TZNAME_MAX    3  /* time zone names can be at least 3 chars */
00154        #define _POSIX_SSIZE_MAX 32767  /* read() must support 32767 byte reads */
00155       
00156        /* Values actually implemented by MINIX (Tables 2-4, 2-5, 2-6, and 2-7). */
00157        /* Some of these old names had better be defined when not POSIX. */
00158        #define _NO_LIMIT        100    /* arbitrary number; limit not enforced */
00159       
00160        #define NGROUPS_MAX        0    /* supplemental group IDs not available */
00161        #if _EM_WSIZE > 2
00162        #define ARG_MAX        16384    /* # bytes of args + environ for exec() */
00163        #else
00164        #define ARG_MAX         4096    /* args + environ on small machines */
00165        #endif
00166        #define CHILD_MAX  _NO_LIMIT    /* MINIX does not limit children */
00167        #define OPEN_MAX          20    /* # open files a process may have */
00168        #define LINK_MAX         127    /* # links a file may have */
00169        #define MAX_CANON        255    /* size of the canonical input queue */
00170        #define MAX_INPUT        255    /* size of the type-ahead buffer */
00171        #define NAME_MAX          14    /* # chars in a file name */
00172        #define PATH_MAX         255    /* # chars in a path name */
00173        #define PIPE_BUF        7168    /* # bytes in atomic write to a pipe */
00174        #define STREAM_MAX        20    /* must be the same as FOPEN_MAX in stdio.h */
00175        #define TZNAME_MAX         3    /* maximum bytes in a time zone name is 3 */
00176        #define SSIZE_MAX      32767    /* max defined byte count for read() */
00177       
00178        #endif /* _POSIX_SOURCE */
00179       
00180        #endif /* _LIMITS_H */
回复

使用道具 举报

发表于 2002-11-27 11:50:46 | 显示全部楼层
这些定义的常量应该是后边要用到的,和数据类型没有关系吧?数据类型应该是和编译器相关的。我在比较原始的UNIX的源代码中没有发现数据类型的定义,也没有这里所说的这些常量的定义。
回复

使用道具 举报

发表于 2002-11-27 11:52:44 | 显示全部楼层
因为所有的编译器都规定char为8bits所以他可以define。关键要看这些define用到了什么地方?如果按照你的说法,那我如果用汇编写一段程序,不需要操作系统就能运行是,我定义的dd,db怎么办?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-5-9 06:24 , Processed in 0.082030 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表