Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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; 

I see it a lot in C code meant to deal closely with hardware—I can't help but think that they're related.

like image 446
Kevin Griffin Avatar asked Oct 23 '08 22:10

Kevin Griffin


People also ask

What does _t mean in C?

The C gurus have a method to their madness when it comes to naming these variables. The _t stands for something. It's very consistent on purpose. The _t implies a typedef, a defined data type. The typedef is based on an existing type.

What is _t in uint32_t?

The _t data types are typedef types in the stdint. h header, while int is a built-in fundamental data type to C. The _t datatypes are only available if stdint. h exists. The fundamental data types like int , however, are guaranteed to exist.

What is meant by typedef in C?

typedef is a reserved keyword in the programming languages C and C++. It is used to create an additional name (alias) for another data type, but does not create a new type, except in the obscure case of a qualified typedef of an array type where the typedef qualifiers are transferred to the array element type.

What does _t mean in a typedef?

It means type. size_t is the size type. The _t does not inherently have any special meaning. But it has fallen into common use to add the _t suffix to typedef's. You may be more familiar with common C practices for variable naming...

What is _T in C programming?

It is a standard naming convention for data types, usually defined by typedefs. A lot of C code that deals with hardware registers uses C99-defined standard names for signed and unsigned fixed-size data types. As a convention, these names are in a standard header file (stdint.h), and end with _t.

Can you end a variable name with _T?

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.

What are the different types of iNTS in C?

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>.


1 Answers

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.

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.

like image 71
Jonathan Leffler Avatar answered Nov 14 '22 03:11

Jonathan Leffler