Language design pointer definition

R

rafaelolg

In the definition of a pointer, why don't a keyword is used instead of
"*"?
The use of "*" does not make confusion with the * operator?
Something like:

int pointer a;
int b;
a=&b;
*a=10;

Thanks.
 
M

Michael Mair

rafaelolg said:
In the definition of a pointer, why don't a keyword is used instead of
"*"?
The use of "*" does not make confusion with the * operator?
Something like:

int pointer a;
int b;
a=&b;
*a=10;

No, * is never ambiguous in context.
If this does not satisfy you, then you need replacements for
other doubly used characters, too: "&", "#", ",", ";", ":", "(",
")", "<", ">" come to mind but maybe I could find some more.

Cheers
Michael
 
M

Malcolm

rafaelolg said:
In the definition of a pointer, why don't a keyword is used instead of
"*"?
The use of "*" does not make confusion with the * operator?
Something like:

int pointer a;
int b;
a=&b;
*a=10;
One reason is that you can have multiple levels of indirection.

int *ptr;
int **2dptr;
int ***3dptr;

It's easier to see when you use the * syntax. I agree, the choice of an
asterisk was confusing, as was the use of the same symbol to declare and to
dereference a pointer.
 
B

Ben Pfaff

rafaelolg said:
In the definition of a pointer, why don't a keyword is used instead of
"*"?
The use of "*" does not make confusion with the * operator?

The idea is that declaration and use look similar. That is,
declaring a pointer and dereferencing a pointer take the same
syntax. The same goes for declaring and invoking a function, and
so on.
 

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

Staff online

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top