什么是一个type后跟_T(下划线-T)再present? [英] What does a type followed by _t (underscore-t) represent?
问题描述
这似乎是一个简单的问题,但我不能与堆栈溢出的搜索或谷歌找到它。什么是一个类型后跟一个 _t
是什么意思?如
This seems like a simple question, but I can't find it with the Stack Overflow search or Google. What does a type followed by a _t
mean? Such as
int_t anInt;
我看到了很多用C code旨在密切处理硬件我不禁觉得他们的关系。
I see it a lot in C code meant to deal closely with hardware—I can't help but think that they're related.
推荐答案
由于道格拉斯·梅尔指出,它基本上代表类型名称。因此,你会不明智的结束与 _t
'变量或函数的名称,因为它可能会导致一些混乱。以及为size_t
中,C89标准定义 wchar_t的
, off_t
, ptrdiff_t的
,也许其他一些我忘了。 C99标准定义了很多额外的类型,如 uintptr_t形式
,的还会将intmax_t
,中int8_t
, uint_least16_t
, uint_fast32_t
,等等。 stdint.h> 但多数情况下,你会使用< inttypes.h>
&LT正式确定>这(异常标准C头)包括< stdint.h>
。它(< inttypes.h>
)还定义了宏与的printf()
和<$ C $使用C> scanf()的。
As Douglas Mayle noted, it basically denotes a type name. Consequently, you would be ill-advised to end variable or function names with '_t
' since it could cause some confusion. As well as size_t
, the C89 standard defines wchar_t
, off_t
, ptrdiff_t
, and probably some others I've forgotten. The C99 standard defines a lot of extra types, such as uintptr_t
, intmax_t
, int8_t
, uint_least16_t
, uint_fast32_t
, and so on. These new types are formally defined in <stdint.h>
but most often you will use <inttypes.h>
which (unusually for standard C headers) includes <stdint.h>
. It (<inttypes.h>
) also defines macros for use with the printf()
and scanf()
.
马特·柯蒂斯指出,没有在后缀编译器没有意义;它是一种以人为本的约定。
As Matt Curtis noted, there is no significance to the compiler in the suffix; it is a human-oriented convention.
不过,你也应该注意到,POSIX定义了很多的 _t
结尾的额外的类型名字,并保留实施的后缀。这意味着,如果你是在POSIX相关系统的工作,并约定定义你自己的类型名称是不明智的。我工作,对系统做了(超过20岁);我们经常得到通过定义类型具有相同的名称,我们定义系统绊倒。
However, you should also note that POSIX defines a lot of extra type names ending in '_t
', and reserves the suffix for the implementation. That means that if you are working on POSIX-related systems, defining your own type names with the convention is ill-advised. The system I work on has done it (for more than 20 years); we regularly get tripped up by systems defining types with the same name as we define.
这篇关于什么是一个type后跟_T(下划线-T)再present?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!