typedef aliasing

J

James Brown

All,

Say I have the following typedef statement:

typedef int * x;

Is it right to say that 'x' is an alias to a pointer-to-int, or that 'x *'
is a an alias to an 'int' ?

thanks,
James
 
R

Richard Heathfield

James Brown said:
All,

Say I have the following typedef statement:

typedef int * x;

Is it right to say that 'x' is an alias to a pointer-to-int, or that 'x *'
is a an alias to an 'int' ?

Strictly speaking, x is not an alias at all. It's a synonym for the type
"int *". But I for one would not consider it unreasonable to say "x is a
synonym for int *". x *, however, would not mean "int".

typedef int *x; /* x is a synonym for "pointer to int" */

x *p; /* p is a pointer to a pointer to int */
 
J

Jens Thoms Toerring

James Brown said:
Say I have the following typedef statement:
typedef int * x;
Is it right to say that 'x' is an alias to a pointer-to-int

I guess you can call it that. But I would prefer to call it what
it is, a typedef, in order to distinguish it from e.g.

#define x int *

which you also could call an "alias" (perhaps with even more
justification).
or that 'x *' is a an alias to an 'int' ?

No. If you have e.g. a variable definition like

x *y;

'y' will be a pointer-to-pointer-to-int - but I would not call
the "x *" bit an alias, neither for an int nor for pointer-to-
pointer-to-int.
Regards, Jens
 
J

James Brown

Richard Heathfield said:
James Brown said:


Strictly speaking, x is not an alias at all. It's a synonym for the type
"int *". But I for one would not consider it unreasonable to say "x is a
synonym for int *". x *, however, would not mean "int".

typedef int *x; /* x is a synonym for "pointer to int" */

x *p; /* p is a pointer to a pointer to int */

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)

ok thankyou for the clarification.

james
 
J

James Brown

Jens Thoms Toerring said:
I guess you can call it that. But I would prefer to call it what
it is, a typedef, in order to distinguish it from e.g.

#define x int *

which you also could call an "alias" (perhaps with even more
justification).


No. If you have e.g. a variable definition like

x *y;

'y' will be a pointer-to-pointer-to-int - but I would not call
the "x *" bit an alias, neither for an int nor for pointer-to-
pointer-to-int.
Regards, Jens

great, thanks for the clarification

james
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top