473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

cv_qualifier in declarator grammar section

xxx
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!
Jul 22 '05 #1
7 2186
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
Jul 22 '05 #2
xxx
// 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?
Jul 22 '05 #3
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
Jul 22 '05 #4
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
Jul 22 '05 #5
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
Jul 22 '05 #6
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
Jul 22 '05 #7
xxx
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:xm*****************@newsread1.mlpsca01.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 =)
Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Peri | last post by:
I'm trying to create Python parser/interpreter using ANTLR. Reading grammar from language refference I found: or_expr::= xor_expr | or_expr "|" xor_expr For me it looks like infinite recursion....
0
by: kk | last post by:
..NET Winforms Control for Spell and grammar check with formatting capabilitie ------------------------------------------------------------------------------------------- Need a control which has...
0
by: Gil | last post by:
Hope this is the right group to post to. I compiled C++ code that ran fine on Windows with VisualStudio 6.0. I then moved the code to Solaris 9 and compiled with g++, but am getting the...
2
by: Chris Gordon-Smith | last post by:
I am currently in India and have treated myself to the Indian reprint of O'Reilly's "C++ In A Nutshell". (Books in India come in at 1/3 to 1/2 of the price in Britain.) I thought that I would...
0
by: Alex Sedow | last post by:
Standart describe grammar for events as (in EBNF): event-declaration: "event" type variable-declarators ";" "event" type member-name "{" event-accessor-declarations "}" ...
7
by: anjogasa | last post by:
In the midst of reading "The C++ Programming Language", the latest edition by Stroustrup, and I find myself butting my head against a few paragraphs. I have searched the errata on the website, and...
29
by: zoltan | last post by:
Hi, The scenario is like this : struct ns_rr { const u_char* rdata; }; The rdata field contains some fields such as :
5
by: Remco van Engelen | last post by:
Hello, I have a question regarding the ISO C grammar. The syntax of a direct-declarator reads (section A.2.2, page 413 in my copy; the (R1) is just to 'name' the rule for later reference): ...
10
by: mdh | last post by:
Sorry in advance if this is really dumb, but I am trying to get my head around exactly what the declarator is. In the FAQ, 1.21, part of it says "C declarations ....come in 2 parts, a base type and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.