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.

Community
  • 1
  • 1
willc2
  • 38,991
  • 25
  • 88
  • 99
  • 4
    Duplicate: http://stackoverflow.com/questions/231760/what-does-a-type-followed-by-t-underscore-t-represent – Corbin March Sep 08 '09 at 00:47
  • This is a two-part question but everyone is getting hung up on the first part. – willc2 Sep 08 '09 at 01:00
  • edited question to make that more clear. – willc2 Sep 08 '09 at 01:03
  • The second part can be answered by "C Standard" and POSIX (see http://www.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). – Jonathan Leffler Sep 08 '09 at 01:03
  • Fastest closers in the west :( – willc2 Sep 08 '09 at 01:04
  • 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 - http://apr.apache.org/) library for examples; see also ICU (http://icu-project.org/) for more examples, and (in C++) the Boost (http://www.boost.org/) libraries. – Jonathan Leffler Sep 08 '09 at 01:08

3 Answers3

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.

Sufian
  • 8,627
  • 4
  • 22
  • 24
  • 2
    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 ``, for example, and gid_t, uid_t, mode_t, and ... – Jonathan Leffler Sep 08 '09 at 00:57
3

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

nairdaen
  • 1,037
  • 2
  • 11
  • 19
3

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

John Bode
  • 119,563
  • 19
  • 122
  • 198
  • 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. – Chris Lutz Sep 08 '09 at 00:57
  • 2
    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 . 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. – Jonathan Leffler Sep 08 '09 at 01:00