What does the postfix "_t" stand for in C? [duplicate]
Asked Answered
H

3

22

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

While typing in my IDE (Xcode), autocomplete pops up already-defined words when I'm partway thru entering some variable name. I occasionally see names that have '_t' at the end of them.

  1. What naming convention is that and what does it mean?

  2. Is there a reference document to look up pre- and post-fixes in common use?

Searching with the term "postfix" gives me a lot of GoogleNoise about the mail server of the same name.

Haiti answered 8/9, 2009 at 0:42 Comment(6)
Duplicate: #232260Bearce
This is a two-part question but everyone is getting hung up on the first part.Haiti
edited question to make that more clear.Haiti
The second part can be answered by "C Standard" and POSIX (see opengroup.org/onlinepubs/9699919799/toc.htm) and your system manual pages. AFAICR, Microsoft doesn't use the '_t' convention in its own code except when following a standard (or, at least, it is not as pervasive a convention in Windows as it is in the Unix/Linux world).Catercorner
Fastest closers in the west :(Haiti
The POSIX standard reserves names ending '_t' when you include POSIX headers. I don't think there are any widespread prefix conventions; people use a few characters, often but not necessarily followed by an underscore, to generate their own namespace. See the Apache Portable Runtime (apr - apr.apache.org) library for examples; see also ICU (icu-project.org) for more examples, and (in C++) the Boost (boost.org) libraries.Catercorner
O
16

The t stands for "type" or "typedef." You'll see a lot of POSIX headers (and others) with time_t, size_t, and others. These which hold (not necessarily defined) specific bit-sizes based on the operating system and machine architecture.

Oilla answered 8/9, 2009 at 0:48 Comment(1)
Also in standard C: size_t, wchar_t, wint_t, clock_t, not to mention the integer types such as int8_t, uint16_t, ... Actually, all the 'POSIX' types mentioned in the answer are defined first in the C standard and only secondarily in POSIX (because it uses the C standard). There are plenty of POSIX-only types ending in '_t' too: ino_t, dev_t appear in <sys/stat.h>, for example, and gid_t, uid_t, mode_t, and ...Catercorner
H
3

based only on my own experience, the "_t" postfix means "data type". In other words, it's a datatype defined used typedef.

Holograph answered 8/9, 2009 at 0:47 Comment(0)
W
3

The "_t" suffix is a convention for data type names such as size_t or wchar_t. It's not used consistently.

Wort answered 8/9, 2009 at 0:49 Comment(2)
I believe the _t suffix was largely POSIX, but then ANSI decided to incorporate some POSIX features as being kind of important. I can't be sure of that, but the first POSIX standard was released in 1988, so they were definitely happening around the same time.Brand
The first C standard was released in 1989, but was largely ready a year or two earlier as the (ANSI) C standard committee tried to get final agreement on the I18N/G11N/L10N aspects of the standard - in particular <locale.h>. But you're right - the (IEEE) POSIX and C standards were developed at very much the same time. The ISO POSIX standard was first released in 1990, the same year as ISO C, IIRC.Catercorner

© 2022 - 2024 — McMap. All rights reserved.