James Brown wrote:[color=blue]
> I am defining the following typedefs:
>
> typedef int* pint;
> typedef pint* ppint;
> typedef ppint* pppint;
>
> taking the last typedef - "pppint" - would this be referred to as:
>
> an alias to type "ppint *" or
> an alias to type "int ***"
>
> Or rather, how is it treated by the compiler and the language?
>
> I think it's the latter, could anyone just clarify this please? The former
> would produce a kind of "type hierarchy" which chained typedef's together
> in a "parent/child" relationship, whereas the latter is just a simple
> type-renaming
> which always refers to the base type.
>
> (I am writing a _very_ simple compiler which just parses basic
> types+typedefs
> and want to represent types in the same way a C compiler would).[/color]
It is not important how you represent types at an intermediate
stage; in the end, however, you have to arrive at "int ***".
What you do in between is entirely yours to say, as there is no
special translation phase dedicated to resolving typedefs
specified in the standard.
Some remarks:
- typedef has the same syntax as a storage class specifier, i.e.
you could replace it by "extern" or "register".
- typedef int *pint;
const pint p;
gives you the same effect as
int * const p;
- if you want to exactly know how a compiler does it, then get
the source of one and have a look at it
- if you want to know what demands are there around typedef, have
a look at the C99 last public draft (google for N869) or the C05
last public draft (N1124) or the C89 one
(
http://danpop.home.cern.ch/danpop/ansi.c)
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.