<s>
typedef	B-Language
is	O
a	O
reserved	O
keyword	O
in	O
the	O
programming	O
languages	O
C	B-Language
,	O
C++	B-Language
,	O
and	O
Objective-C	B-Language
.	O
</s>
<s>
It	O
is	O
used	O
to	O
create	O
an	O
additional	O
name	O
(	O
alias	O
)	O
for	O
another	O
data	O
type	O
,	O
but	O
does	O
not	O
create	O
a	O
new	O
type	O
,	O
except	O
in	O
the	O
obscure	O
case	O
of	O
a	O
qualified	B-Language
typedef	B-Language
of	O
an	O
array	O
type	O
where	O
the	O
typedef	B-Language
qualifiers	O
are	O
transferred	O
to	O
the	O
array	O
element	O
type	O
.	O
</s>
<s>
As	O
such	O
,	O
it	O
is	O
often	O
used	O
to	O
simplify	O
the	O
syntax	O
of	O
declaring	O
complex	O
data	B-General_Concept
structures	I-General_Concept
consisting	O
of	O
struct	B-Application
and	O
union	O
types	O
,	O
although	O
it	O
is	O
also	O
commonly	O
used	O
to	O
provide	O
specific	O
descriptive	O
type	O
names	O
for	O
integer	O
data	O
types	O
of	O
varying	O
sizes	O
.	O
</s>
<s>
A	O
typedef	B-Language
declaration	O
follows	O
the	O
same	O
syntax	O
as	O
declaring	O
any	O
other	O
C	B-Language
identifier	O
.	O
</s>
<s>
The	O
keyword	O
typedef	B-Language
itself	O
is	O
a	O
specifier	O
which	O
means	O
that	O
while	O
it	O
typically	O
appears	O
at	O
the	O
start	O
of	O
the	O
declaration	O
,	O
it	O
can	O
also	O
appear	O
after	O
the	O
type	O
specifiers	O
or	O
between	O
two	O
of	O
them	O
.	O
</s>
<s>
In	O
the	B-Language
C	I-Language
standard	I-Language
library	I-Language
and	O
in	O
POSIX	O
specifications	O
,	O
the	O
identifier	O
for	O
the	O
typedef	B-Language
definition	O
is	O
often	O
suffixed	O
with	O
,	O
such	O
as	O
in	O
size_t	O
and	O
time_t	O
.	O
</s>
<s>
A	O
typedef	B-Language
declaration	O
may	O
be	O
used	O
as	O
documentation	O
by	O
indicating	O
the	O
meaning	O
of	O
a	O
variable	O
within	O
the	O
programming	O
context	O
,	O
e.g.	O
,	O
it	O
may	O
include	O
the	O
expression	O
of	O
a	O
unit	O
of	O
measurement	O
or	O
counts	O
.	O
</s>
<s>
However	O
,	O
the	O
use	O
of	O
typedef	B-Language
declarations	O
in	O
the	O
second	O
code	O
block	O
makes	O
it	O
clear	O
that	O
the	O
two	O
variables	O
,	O
while	O
representing	O
the	O
same	O
data	O
type	O
,	O
store	O
different	O
or	O
incompatible	O
data	O
.	O
</s>
<s>
However	O
,	O
the	O
indication	O
is	O
for	O
the	O
programmer	O
only	O
;	O
the	O
C/C	O
++	O
compiler	O
considers	O
both	O
variables	O
to	O
be	O
of	O
type	O
and	O
does	O
not	O
flag	O
type	O
mismatch	O
warnings	O
or	O
errors	O
for	O
"	O
wrong	O
"	O
argument	O
types	O
for	O
in	O
the	O
code	O
snippet	O
below	O
:	O
</s>
<s>
A	O
typedef	B-Language
may	O
be	O
used	O
to	O
simplify	O
the	O
declaration	O
of	O
a	O
compound	O
type	O
(	O
struct	B-Application
,	O
union	O
)	O
or	O
pointer	O
type	O
.	O
</s>
<s>
A	O
variable	O
declaration	O
of	O
this	O
type	O
in	O
C	B-Language
also	O
requires	O
the	O
keyword	O
,	O
but	O
it	O
may	O
be	O
omitted	O
in	O
C++	B-Language
:	O
</s>
<s>
The	O
structure	B-Language
declaration	O
and	O
typedef	B-Language
may	O
also	O
be	O
combined	O
into	O
a	O
single	O
statement	O
:	O
</s>
<s>
In	O
C++	B-Language
,	O
in	O
contrast	O
to	O
C	B-Language
,	O
the	O
keywords	O
,	O
,	O
and	O
are	O
optional	O
in	O
variable	O
declarations	O
that	O
are	O
separate	O
from	O
the	O
definitions	O
,	O
as	O
long	O
as	O
there	O
is	O
no	O
ambiguity	O
to	O
another	O
identifier	O
:	O
</s>
<s>
A	O
notorious	O
example	O
where	O
even	O
C++	B-Language
needs	O
the	O
keyword	O
is	O
the	O
POSIX	O
stat	B-Language
system	I-Language
call	I-Language
that	O
uses	O
a	O
struct	B-Application
of	O
the	O
same	O
name	O
in	O
its	O
arguments	O
:	O
</s>
<s>
Here	O
both	O
C	B-Language
as	O
well	O
as	O
C++	B-Language
need	O
the	O
keyword	O
in	O
the	O
parameter	O
definition	O
.	O
</s>
<s>
The	O
typedef	B-Language
may	O
be	O
used	O
to	O
define	O
a	O
new	O
pointer	O
type	O
.	O
</s>
<s>
Using	O
typedef	B-Language
to	O
define	O
a	O
new	O
pointer	O
type	O
may	O
sometimes	O
lead	O
to	O
confusion	O
.	O
</s>
<s>
This	O
is	O
because	O
a	O
type	O
defined	O
by	O
typedef	B-Language
is	O
a	O
type	O
,	O
not	O
an	O
expansion	O
.	O
</s>
<s>
Again	O
,	O
because	O
typedef	B-Language
defines	O
a	O
type	O
,	O
not	O
an	O
expansion	O
,	O
declarations	O
that	O
use	O
the	O
const	O
qualifier	O
can	O
yield	O
unexpected	O
or	O
unintuitive	O
results	O
.	O
</s>
<s>
Typedefs	B-Language
can	O
also	O
simplify	O
definitions	O
or	O
declarations	O
for	O
structure	B-Language
pointer	O
types	O
.	O
</s>
<s>
Using	O
typedef	B-Language
,	O
the	O
above	O
code	O
can	O
be	O
rewritten	O
like	O
this	O
:	O
</s>
<s>
In	O
C	B-Language
,	O
one	O
can	O
declare	O
multiple	O
variables	O
of	O
the	O
same	O
type	O
in	O
a	O
single	O
statement	O
,	O
even	O
mixing	O
structure	B-Language
with	O
pointer	O
or	O
non-pointers	O
.	O
</s>
<s>
By	O
defining	O
the	O
typedef	B-Language
,	O
it	O
is	O
assured	O
that	O
all	O
variables	O
are	O
structure	B-Language
pointer	O
types	O
,	O
or	O
say	O
,	O
that	O
each	O
variable	O
is	O
a	O
pointer	O
type	O
pointing	O
to	O
a	O
structure	B-Language
type	I-Language
.	O
</s>
<s>
The	O
preceding	O
code	O
may	O
be	O
rewritten	O
with	O
typedef	B-Language
specifications	O
:	O
</s>
<s>
When	O
a	O
function	O
returns	O
a	O
function	B-Language
pointer	I-Language
,	O
it	O
can	O
be	O
even	O
more	O
confusing	O
without	O
typedef	B-Language
.	O
</s>
<s>
The	O
following	O
is	O
the	O
function	O
prototype	O
of	O
signal(3 )	O
from	O
FreeBSD	B-Operating_System
:	O
</s>
<s>
A	O
novice	O
programmer	O
may	O
even	O
assume	O
that	O
the	O
function	O
accepts	O
a	O
single	O
as	O
its	O
argument	O
and	O
returns	O
nothing	O
,	O
but	O
in	O
reality	O
it	O
also	O
needs	O
a	O
function	B-Language
pointer	I-Language
and	O
returns	O
another	O
function	B-Language
pointer	I-Language
.	O
</s>
<s>
A	O
typedef	B-Language
can	O
also	O
be	O
used	O
to	O
simplify	O
the	O
definition	O
of	O
array	O
types	O
.	O
</s>
<s>
A	O
typedef	B-Language
is	O
created	O
using	O
type	O
definition	O
syntax	O
but	O
can	O
be	O
used	O
as	O
if	O
it	O
were	O
created	O
using	O
type	O
cast	O
syntax	O
.	O
</s>
<s>
Thus	O
,	O
the	O
typedef	B-Language
can	O
be	O
used	O
by	O
programmers	O
who	O
do	O
not	O
wish	O
to	O
figure	O
out	O
how	O
to	O
convert	O
definition	O
syntax	O
to	O
type	O
cast	O
syntax	O
.	O
</s>
<s>
Without	O
the	O
typedef	B-Language
,	O
it	O
is	O
generally	O
not	O
possible	O
to	O
use	O
definition	O
syntax	O
and	O
cast	O
syntax	O
interchangeably	O
.	O
</s>
<s>
In	O
C++	B-Language
type	O
names	O
can	O
be	O
complex	O
,	O
and	O
typedef	B-Language
provides	O
a	O
mechanism	O
to	O
assign	O
a	O
simple	O
name	O
to	O
the	O
type	O
.	O
</s>
<s>
C++11	B-Language
introduced	O
the	O
possibility	O
to	O
express	O
typedefs	B-Language
with	O
instead	O
of	O
.	O
</s>
<s>
C++03	O
does	O
not	O
provide	O
templated	B-Application
typedefs	B-Language
.	O
</s>
<s>
However	O
,	O
if	O
one	O
is	O
willing	O
to	O
accept	O
in	O
lieu	O
of	O
,	O
then	O
it	O
is	O
possible	O
to	O
achieve	O
the	O
desired	O
result	O
via	O
a	O
typedef	B-Language
within	O
an	O
otherwise	O
unused	O
templated	B-Application
class	O
or	O
struct	B-Application
:	O
</s>
<s>
In	O
C++11	B-Language
,	O
templated	B-Application
typedefs	B-Language
are	O
added	O
with	O
the	O
following	O
syntax	O
,	O
which	O
requires	O
the	O
keyword	O
rather	O
than	O
the	O
keyword	O
.	O
</s>
<s>
(	O
See	O
template	B-Application
aliases	O
.	O
)	O
</s>
<s>
In	O
SystemVerilog	B-Language
,	O
typedef	B-Language
behaves	O
exactly	O
the	O
way	O
it	O
does	O
in	O
C	B-Language
and	O
C++	B-Language
.	O
</s>
<s>
In	O
many	O
statically	O
typed	O
functional	O
languages	O
,	O
like	O
Haskell	B-Language
,	O
Miranda	B-Language
,	O
OCaml	B-Language
,	O
etc.	O
,	O
one	O
can	O
define	O
type	O
synonyms	O
,	O
which	O
are	O
the	O
same	O
as	O
typedefs	B-Language
in	O
C	B-Language
.	O
An	O
example	O
in	O
Haskell	B-Language
:	O
</s>
<s>
In	O
Seed7	B-Language
the	O
definition	O
of	O
a	O
constant	O
type	O
is	O
used	O
to	O
introduce	O
a	O
synonym	O
for	O
a	O
type	O
:	O
</s>
<s>
In	O
Swift	B-Application
,	O
one	O
uses	O
the	O
keyword	O
to	O
create	O
a	O
typedef	B-Language
:	O
</s>
<s>
C#	B-Application
contains	O
a	O
feature	O
which	O
is	O
similar	O
to	O
the	O
typedef	B-Language
or	O
the	O
syntax	O
of	O
C++	B-Language
.	O
</s>
<s>
In	O
D	B-Application
the	O
keyword	O
allows	O
to	O
create	O
type	O
or	O
partial	O
type	O
synonyms	O
.	O
</s>
<s>
Kernighan	O
and	O
Ritchie	O
stated	O
two	O
reasons	O
for	O
using	O
a	O
typedef	B-Language
.	O
</s>
<s>
Instead	O
of	O
having	O
to	O
change	O
a	O
type	O
in	O
every	O
appearance	O
throughout	O
the	O
program	O
's	O
source	O
files	O
,	O
only	O
a	O
single	O
typedef	B-Language
statement	O
needs	O
to	O
be	O
changed	O
.	O
</s>
<s>
size_t	O
and	O
ptrdiff_t	O
in	O
<stdlib.h>	O
are	O
such	O
typedef	B-Language
names	O
.	O
</s>
<s>
Second	O
,	O
a	O
typedef	B-Language
can	O
make	O
a	O
complex	O
definition	O
or	O
declaration	O
easier	O
to	O
understand	O
.	O
</s>
<s>
Some	O
programmers	O
are	O
opposed	O
to	O
the	O
extensive	O
use	O
of	O
typedefs	B-Language
.	O
</s>
<s>
Most	O
arguments	O
center	O
on	O
the	O
idea	O
that	O
typedefs	B-Language
simply	O
hide	O
the	O
actual	O
data	O
type	O
of	O
a	O
variable	O
.	O
</s>
<s>
For	O
example	O
,	O
Greg	O
Kroah-Hartman	O
,	O
a	O
Linux	B-Operating_System
kernel	I-Operating_System
hacker	O
and	O
documenter	O
,	O
discourages	O
their	O
use	O
for	O
anything	O
except	O
function	O
prototype	O
declarations	O
.	O
</s>
