Language design pointer definition

Discussion in 'C Programming' started by rafaelolg, Oct 23, 2005.

  1. rafaelolg

    rafaelolg Guest

    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.
     
    rafaelolg, Oct 23, 2005
    #1
    1. Advertising

  2. rafaelolg

    Michael Mair Guest

    rafaelolg wrote:
    > 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
    --
    E-Mail: Mine is an /at/ gmx /dot/ de address.
     
    Michael Mair, Oct 23, 2005
    #2
    1. Advertising

  3. rafaelolg

    Malcolm Guest

    "rafaelolg" <> wrote
    > 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.
     
    Malcolm, Oct 23, 2005
    #3
  4. rafaelolg

    Ben Pfaff Guest

    "rafaelolg" <> writes:

    > 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.
    --
    Peter Seebach on C99:
    "[F]or the most part, features were added, not removed. This sounds
    great until you try to carry a full-sized printout of the standard
    around for a day."
     
    Ben Pfaff, Oct 23, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jianli Shen
    Replies:
    1
    Views:
    604
    Victor Bazarov
    Mar 13, 2005
  2. Ark
    Replies:
    1
    Views:
    437
    Chris Torek
    Aug 7, 2004
  3. Replies:
    10
    Views:
    717
    Chris Torek
    Feb 4, 2005
  4. Jon Slaughter
    Replies:
    4
    Views:
    460
    Jon Slaughter
    Oct 26, 2005
  5. Pierre Yves
    Replies:
    2
    Views:
    500
    Pierre Yves
    Jan 10, 2008
Loading...

Share This Page