C programming: _t?

brjames

Member
Apr 25, 2001
168
0
0
What does it mean when there is a _t as part of a data type? For example: page_t, caddr_t, sigset_t, req_entry_t

Is this some type of standard nomenclature? If so what does it mean? Will I break stuff if I ignore this convention?
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
AFAIK, it's just a way of splitting up variable names to make them easier to read (but harder to type :))
Now IIRC, by convention, variables with double leading and/or trailing underscores like __MyVar__ are variables, functions or macros within the libraries, so you should avoid using this convention to avoid possible conflicts.
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
Well it's not "_t" itself but foo_t, etc. I have noticed this practice a lot myself. And about the underscores, I was just reading the "good C coding practices" thing on developerworks that got posted to /., and it said that you shouldn't use anything that begins or ends with any number of underscores, as those are often used by "system" libraries or whatever. But then again, so are a lot of other names, so I don't see why those are a special case.
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
Originally posted by: BingBongWongFooey
Well it's not "_t" itself but foo_t, etc. I have noticed this practice a lot myself. And about the underscores, I was just reading the "good C coding practices" thing on developerworks that got posted to /., and it said that you shouldn't use anything that begins or ends with any number of underscores, as those are often used by "system" libraries or whatever. But then again, so are a lot of other names, so I don't see why those are a special case.

I think the convention is that, in system libraries, names that are exposed to the global namespace are prepended with underscores ... for example, the top of fstream.h:

#ifndef _FSTREAM_H
#define _FSTREAM_H
#ifdef __GNUG__
#pragma interface
#endif
#include <iostream.h>

extern "C++" {
class fstreambase : virtual public ios {
#ifdef _IO_NEW_STREAMS
mutable filebuf __my_fb; // mutable so rdbuf() can be const
#endif
void __fb_init ();
public:
 

Reel

Diamond Member
Jul 14, 2001
4,484
0
76
I think I actually ran into this just recently. I am working on a project involving the kernel of OpenBSD. Here is a line of code from the kernel file kern_synch.c

fixpt_t ccpu = 0.95122942450071400909 * FSCALE; /* exp(-1/20) */

I believe the question is what does the _t in fixpt_t refer to? I am clueless as to what the answer is but I believe that the answers above this post may not be answering the right question.
 

manly

Lifer
Jan 25, 2000
13,020
3,777
136
Like EmperorRob said, it generally stands for typedef. It's a common code convention for UNIX systems.