C中“size_t”的意义是什么?(复制)

时间:2022-10-07 16:09:04

Possible Duplicate:
What does a type followed by _t (underscore-t) represent?

可能的重复:类型后面的_t (underscore-t)代表什么?

I know what the size_t is. It's an integer type depends on platform. But I cannot figure out what the t stand for. And there are many typed which suffixes with _t. What's the _t means?

我知道size_t是什么。它是一个整数类型取决于平台。但我不知道t代表什么。有很多类型的后缀都是_t。_t意味着什么?

2 个解决方案

#1


8  

"t" means "type" (or to some people, typedef, which is the command used to create them). size_t is the type used to specify memory sizes. time_t on the other hand, is the type used to specify time spans. They generally happen to refer to the same underlying type (a 64-bit or 32-bit integer, depending on the platform), but the label helps keep them straight conceptually so that the implementation details can be hammered out by the compiler.

“t”的意思是“类型”(或者对某些人来说,typedef是用来创建它们的命令)。size_t是用于指定内存大小的类型。另一方面,time_t是用于指定时间跨度的类型。它们通常会引用相同的底层类型(根据平台的不同,这是一个64位或32位的整数),但是标签可以帮助保持它们的概念,以便实现细节可以由编译器来确定。

For example, time_t used to be a 32-bit integer, meaning that the clock would roll over in 2038. But on most 64-bit architectures, they've expanded time_t to be a 64-bit integer, which means that 64-bit systems won't have a "year-2038" problem. Since code that deals with unix timestamps uses the type name time_t rather than int to refer to these values, everything will "just work" when you simply recompile the code for your new architecture.

例如,time_t以前是一个32位的整数,这意味着时钟将在2038年滚动。但是在大多数64位体系结构中,它们将time_t扩展为一个64位整数,这意味着64位系统不会有“一年2038”的问题。由于处理unix时间戳的代码使用类型名称time_t(而不是int)来引用这些值,所以当您简单地重新编译新架构的代码时,一切都会“工作”。

#2


9  

In my experience the _t is a conventional suffix for types declared using typedef.

在我的经验中,_t是使用typedef声明的类型的常规后缀。

e.g.

如。

typedef int myInt_t;

etc...

等等……

#1


8  

"t" means "type" (or to some people, typedef, which is the command used to create them). size_t is the type used to specify memory sizes. time_t on the other hand, is the type used to specify time spans. They generally happen to refer to the same underlying type (a 64-bit or 32-bit integer, depending on the platform), but the label helps keep them straight conceptually so that the implementation details can be hammered out by the compiler.

“t”的意思是“类型”(或者对某些人来说,typedef是用来创建它们的命令)。size_t是用于指定内存大小的类型。另一方面,time_t是用于指定时间跨度的类型。它们通常会引用相同的底层类型(根据平台的不同,这是一个64位或32位的整数),但是标签可以帮助保持它们的概念,以便实现细节可以由编译器来确定。

For example, time_t used to be a 32-bit integer, meaning that the clock would roll over in 2038. But on most 64-bit architectures, they've expanded time_t to be a 64-bit integer, which means that 64-bit systems won't have a "year-2038" problem. Since code that deals with unix timestamps uses the type name time_t rather than int to refer to these values, everything will "just work" when you simply recompile the code for your new architecture.

例如,time_t以前是一个32位的整数,这意味着时钟将在2038年滚动。但是在大多数64位体系结构中,它们将time_t扩展为一个64位整数,这意味着64位系统不会有“一年2038”的问题。由于处理unix时间戳的代码使用类型名称time_t(而不是int)来引用这些值,所以当您简单地重新编译新架构的代码时,一切都会“工作”。

#2


9  

In my experience the _t is a conventional suffix for types declared using typedef.

在我的经验中,_t是使用typedef声明的类型的常规后缀。

e.g.

如。

typedef int myInt_t;

etc...

等等……