cv_qualifier in declarator grammar section

Discussion in 'C++' started by xxx, Jan 4, 2005.

  1. xxx

    xxx Guest

    I am having difficulty seeing why cv_qualifier, which is used as a type
    specifier in the declaration section of the ISO/IEC grammar, is defined in
    the declarator section. A declaration can consist of specifiers followed by
    declarators. Because of the cv_qualifier, I am now confused as to what
    defines a declarator. Can anyone help clear this up for me? Thank you!
     
    xxx, Jan 4, 2005
    #1
    1. Advertising

  2. xxx wrote:
    > I am having difficulty seeing why cv_qualifier, which is used as a type
    > specifier in the declaration section of the ISO/IEC grammar, is defined in
    > the declarator section. A declaration can consist of specifiers followed by
    > declarators. Because of the cv_qualifier, I am now confused as to what
    > defines a declarator. Can anyone help clear this up for me? Thank you!


    Without getting formal (I am not good at it), I think the reason for it to
    be there is that you could write

    const int a;

    and

    int const a;

    , and they'd mean the same thing.

    Victor
     
    Victor Bazarov, Jan 4, 2005
    #2
    1. Advertising

  3. xxx

    xxx Guest

    // cv_qualifier as a specifier when to the left of "x"
    int const x = 123;
    const int x = 123;

    // cv_qualifier as a declarator when to the right of "x"
    int x (123) const;

    Do you mean that everything left to the identifier is part of the type and
    everything to the right is part of the declarator?
     
    xxx, Jan 4, 2005
    #3
  4. xxx wrote:
    > // cv_qualifier as a specifier when to the left of "x"
    > int const x = 123;
    > const int x = 123;
    >
    > // cv_qualifier as a declarator when to the right of "x"
    > int x (123) const;


    I don't think this is valid.

    > Do you mean that everything left to the identifier is part of the type and
    > everything to the right is part of the declarator?


    No, I don't mean that. What problem are you trying to solve, anyway?

    V
     
    Victor Bazarov, Jan 4, 2005
    #4
  5. Victor Bazarov wrote:

    > Without getting formal (I am not good at it), I think the reason for it to
    > be there is that you could write
    >
    > const int a;
    >
    > and
    >
    > int const a;
    >
    > , and they'd mean the same thing.


    Am I right to think that these two statements are the same if it's an
    non pointertype?

    What I mean:
    const int *my_pointer = NULL;
    and
    int const *my_pointer are different things.

    Am I right here?

    Kind regards,
    Nicolas
     
    Nicolas Pavlidis, Jan 4, 2005
    #5
  6. Nicolas Pavlidis wrote:
    > Victor Bazarov wrote:
    >
    >> Without getting formal (I am not good at it), I think the reason for
    >> it to
    >> be there is that you could write
    >>
    >> const int a;
    >>
    >> and
    >>
    >> int const a;
    >>
    >> , and they'd mean the same thing.

    >
    >
    > Am I right to think that these two statements are the same if it's an
    > non pointertype?
    >
    > What I mean:
    > const int *my_pointer = NULL;
    > and
    > int const *my_pointer are different things.
    >
    > Am I right here?


    They mean exactly the same. 'my_pointer' is a pointer to a constant
    integer.

    The source of often seen confusion is the asterisk. E.g.

    const int * p;

    and

    int * const p;

    are _not_ the same. And another example involving this typedef

    typedef int * pint;

    where declarations

    const int * p;

    and

    const pint p;

    are _not_ the same. Reading declarations correctly takes a bit of getting
    used to but it's not that difficult.

    Victor
     
    Victor Bazarov, Jan 4, 2005
    #6
  7. Victor Bazarov wrote:

    > Nicolas Pavlidis wrote:
    >
    >> Victor Bazarov wrote:
    >>
    >>> Without getting formal (I am not good at it), I think the reason for
    >>> it to
    >>> be there is that you could write
    >>>
    >>> const int a;
    >>>
    >>> and
    >>>
    >>> int const a;
    >>>
    >>> , and they'd mean the same thing.

    >>
    >>
    >>
    >> Am I right to think that these two statements are the same if it's an
    >> non pointertype?
    >>
    >> What I mean:
    >> const int *my_pointer = NULL;
    >> and
    >> int const *my_pointer are different things.
    >>
    >> Am I right here?

    >
    >
    > They mean exactly the same. 'my_pointer' is a pointer to a constant
    > integer.


    Ah, ok.

    > The source of often seen confusion is the asterisk. E.g.
    >
    > const int * p;
    >
    > and
    >
    > int * const p;
    >
    > are _not_ the same. And another example involving this typedef
    >
    > typedef int * pint;
    >
    > where declarations
    >
    > const int * p;
    >
    > and
    >
    > const pint p;
    >
    > are _not_ the same. Reading declarations correctly takes a bit of
    > getting used to but it's not that difficult.


    Ok, now it's clear to me, thank you!

    Kind regards,
    Nicolas
     
    Nicolas Pavlidis, Jan 4, 2005
    #7
  8. xxx

    xxx Guest

    "Victor Bazarov" <> wrote in message
    news:xmBCd.34530$01.us.to.verio.net...
    > xxx wrote:
    >> // cv_qualifier as a specifier when to the left of "x"
    >> int const x = 123;
    >> const int x = 123;
    >>
    >> // cv_qualifier as a declarator when to the right of "x"
    >> int x (123) const;

    >
    > I don't think this is valid.
    >
    >> Do you mean that everything left to the identifier is part of the type
    >> and everything to the right is part of the declarator?

    >
    > No, I don't mean that. What problem are you trying to solve, anyway?
    >
    > V


    I should have verified it with MS VC++ 7.1. The "int x (123) const" passed
    with flying colors with GNU C++ 3.2.3.

    Designing a C++ based interpreter is what I'm doing so I would like to make
    sure I understand things before I jump right into implementation.

    I am trying to understand why cv_qualifier is not a specifier. The previous
    syntax may be invalid for declaring constant int, but you could still
    declare "void someclass::func (int value) const" where the const in this
    case is exactly a declarator because it is part of the member's definition
    (as in a member function that doesn't modify any data of the class). I
    understand that it is because of this that the cv is a cv_qualifier rather
    than a cv_specifier because it can appear in two different context. Ah, I
    think I just answered my own question!

    Thank you for helping me realize this =)
     
    xxx, Jan 4, 2005
    #8
    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. Vasileios
    Replies:
    4
    Views:
    479
    Rolf Magnus
    Nov 4, 2003
  2. Gil
    Replies:
    0
    Views:
    459
  3. Per Johansson
    Replies:
    3
    Views:
    1,325
    Mike Wahler
    Nov 7, 2004
  4. Mark
    Replies:
    2
    Views:
    1,449
    Rolf Magnus
    Jan 25, 2005
  5. Remco van Engelen

    C grammar for direct-declarator question

    Remco van Engelen, Sep 14, 2006, in forum: C Programming
    Replies:
    5
    Views:
    375
    Michael Mair
    Sep 14, 2006
Loading...

Share This Page