int_least32_t这个类型到底有什么用?

najiushifeng1111 2011-04-11 12:04:28
C99标准引入了一个头文件stdint.h,在这个头文件中用typedef声明了一个类型,如:
typedef int int_least32_t;
也就是int_least32_t就是int,既然它就是int,为什么C99标准的人要加这么个东西,难道是吃饱了撑着了?
...全文
941 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
najiushifeng1111 2011-04-12
  • 打赏
  • 举报
回复
有没有10位或者24操作系统啊??
najiushifeng1111 2011-04-11
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 luciferisnotsatan 的回复:]
就像名字说的,这个最小32位。你用这个int_least32_t,就不用担心int是16位的情况了。
[/Quote]
还有int_fast32_t,它的声明:
typedef int int_fast32_t;
再看int_fast16_t,它的声明:
typedef int int_fast16_t;
你会看到,它也是int,我就搞不明白,C99标准这些人是干啥呢??
najiushifeng1111 2011-04-11
  • 打赏
  • 举报
回复
我看完了整个头文件,都没有发现条件编辑语句
luciferisnotsatan 2011-04-11
  • 打赏
  • 举报
回复
就像名字说的,这个最小32位。你用这个int_least32_t,就不用担心int是16位的情况了。
ouyh12345 2011-04-11
  • 打赏
  • 举报
回复
上下文中有没有条件编译语句?
najiushifeng1111 2011-04-11
  • 打赏
  • 举报
回复
_W64 int

#ifdef _WIN64
typedef unsigned __int64 uintptr_t;
#else /* _WIN64 */
typedef _W64 unsigned int uintptr_t;
luciferisnotsatan 2011-04-11
  • 打赏
  • 举报
回复
反正就是,编译器要不就不支持,如果支持了int32_t,那就不能违反。
主流的编译器都不会出现那说的那种情况,不然也成不了主流。
luciferisnotsatan 2011-04-11
  • 打赏
  • 举报
回复
如果你的编译器支持32位和64位编译,应该有这个东西吧。或者直接就用了long long
long在64位下是64位,32位下是32位。long long不管32位还是64位,都是64位。基本上编译器都是这么设置这两个内建类型的。

[Quote=引用 18 楼 najiushifeng1111 的回复:]

引用 17 楼 luciferisnotsatan 的回复:
# if __WORDSIZE == 64
typedef long int int64_t;
# else
__extension__
typedef long long int int64_t;
# endif

不知道你的stdint里有没有这行。这里就用宏确定了 int64_t 必须是 64位。
至于char……
[/Quote]
najiushifeng1111 2011-04-11
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 luciferisnotsatan 的回复:]
# if __WORDSIZE == 64
typedef long int int64_t;
# else
__extension__
typedef long long int int64_t;
# endif

不知道你的stdint里有没有这行。这里就用宏确定了 int64_t 必须是 64位。
至于char 和 int8_t,那是那个编译器适用的范围里char就是8bit……
[/Quote]
我找了一天,都没找到这个宏。
luciferisnotsatan 2011-04-11
  • 打赏
  • 举报
回复
# if __WORDSIZE == 64
typedef long int int64_t;
# else
__extension__
typedef long long int int64_t;
# endif

不知道你的stdint里有没有这行。这里就用宏确定了 int64_t 必须是 64位。
至于char 和 int8_t,那是那个编译器适用的范围里char就是8bit。
这就和不同的CPU,指令集不一样。不用去纠结编译器能否把你的C语言转成正确的机器指令。
luciferisnotsatan 2011-04-11
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 najiushifeng1111 的回复:]

这个标准给出来,我看过了,它就是说编译器的制造商必须根据规定,int8_t就必须占用8位,但是看它们的头文件,我感觉似乎不那么严谨,它就是用了个别名,将char换了个名字叫int8_t,char在不同的系统上位数都是不一样的,有的8位,有的16位,还有的32位,所以说编译器的制造商已经违反标准了。
[/Quote]
不同位数,那是编译器编译时就订下的。编译后的机器码上只有寄存器的概念,不存在char,int这种概念。
跨平台,一种是放到那个平台上,用那个平台上的编译器编。另一种是用交叉编译。这两种都会有相对应的int8_t的定义。如果char是16位的,就不会用char去typedef这个int8_t。
najiushifeng1111 2011-04-11
  • 打赏
  • 举报
回复
这个标准给出来,我看过了,它就是说编译器的制造商必须根据规定,int8_t就必须占用8位,但是看它们的头文件,我感觉似乎不那么严谨,它就是用了个别名,将char换了个名字叫int8_t,char在不同的系统上位数都是不一样的,有的8位,有的16位,还有的32位,所以说编译器的制造商已经违反标准了。
luciferisnotsatan 2011-04-11
  • 打赏
  • 举报
回复
http://d.download.csdn.net/down/3123506/fnwzk
这个是C99标准,500多页。你可以看下。
编译器需要对着标准做编译器。

lz难道是华为的员工?想起华为那套MML标准,定义模糊,开发基站的还不一定照着做(开发赶进度)。那标准还会改。。。。。。
luciferisnotsatan 2011-04-11
  • 打赏
  • 举报
回复
我不已经把标准给出来了?
你自己看下7.18 Integer types <stdint.h>

编译器可以不支持标准,但不能违反标准。
7.18.1.1 Exact-width integer types
1 The typedef name intN_t designates a signed integer type with width N, no padding
bits, and a two’s complement representation. Thus, int8_t denotes a signed integer
type with a width of exactly 8 bits.
2 The typedef name uintN_t designates an unsigned integer type with width N. Thus,
uint24_t denotes an unsigned integer type with a width of exactly 24 bits.
3 These types are optional. However, if an implementation provides integer types with
widths of 8, 16, 32, or 64 bits, it shall define the corresponding typedef names.

如果那个编译器把 int8_t作为 8bit长有符号整型意外的类型,你可以大骂那个编译器厂商。不过应该没这个机会。

najiushifeng1111 2011-04-11
  • 打赏
  • 举报
回复
老大,你只需要给出一个确切的字节字即可,那些说法都太笼统,没有任何意义。我们要的是实际状态,而不是理论。任何理论都必须建立在实践之上,实践出真知,理论都可以被推翻。
辰岡墨竹 2011-04-11
  • 打赏
  • 举报
回复
这个问题我在另外那个帖子里已经回复了。看那两个链接。
najiushifeng1111 2011-04-11
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 bokutake 的回复:]
你看到的是32位Linux下GCC x86-32版本用的,Linux的GCC本身就是有平台版本的,要想编译别的平台的,需要用另外版本的编译器和头文件,所以无需条件编译。
[/Quote]
或者这么问:一个32位的GCC编译器,它在XP下(32位系统)运行时,char是多少位?short是多少位,int是多少位,long是多少位?long long是多少位?它在WIN7下(64位系统)运行时,char是多少位?short是多少位,int是多少位,long是多少位?long long是多少位?
najiushifeng1111 2011-04-11
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 bokutake 的回复:]
你看到的是32位Linux下GCC x86-32版本用的,Linux的GCC本身就是有平台版本的,要想编译别的平台的,需要用另外版本的编译器和头文件,所以无需条件编译。
[/Quote]
那我问你一个问题,Microsoft Visual Studio 2010是32位的编译器,它在XP下(32位系统)运行时,char是多少位?short是多少位,int是多少位,long是多少位?long long是多少位?它在WIN7下(64位系统)运行时,char是多少位?short是多少位,int是多少位,long是多少位?long long是多少位?
辰岡墨竹 2011-04-11
  • 打赏
  • 举报
回复
你看到的是32位Linux下GCC x86-32版本用的,Linux的GCC本身就是有平台版本的,要想编译别的平台的,需要用另外版本的编译器和头文件,所以无需条件编译。
luciferisnotsatan 2011-04-11
  • 打赏
  • 举报
回复
http://d.download.csdn.net/down/3123506/fnwzk

想了解标准,看标准,不要看着头文件猜那是干嘛用的。
加载更多回复(2)

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧