473,670 Members | 2,336 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2204
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.********@com Acast.net> wrote in message
news:xm******** *********@newsr ead1.mlpsca01.u s.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
3415
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. And so it says ANTLR. Maybe I don't understand EBNF notation. For me it should look like this. or_expr::= xor_expr | xor_expr "|" xor_expr and in ANTLR grammar file like this:
0
2141
by: kk | last post by:
..NET Winforms Control for Spell and grammar check with formatting capabilitie ------------------------------------------------------------------------------------------- Need a control which has spell and grammar check capabilities to be added to our Visual C# application Our C# application has HTML controls every where in our application used as a control rather than an activex control. The HTML Editor has helped us with text editing...
0
1303
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 following errors : In file included from corba.h:97, from code_ims_c.hh:13, from code_s.hh:11,
2
1826
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 have a look at what Chapter 12 on grammar says about Declarations and Definitions. Now I'm more baffled than when I started. Here's the problem.
0
1112
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 "}" variable-declarators: variable-declarator variable-declarators "," variable-declarator
7
4411
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 since its not in error, my understanding must be. I quote the following: - >From 4.9.1 - The Structure of a Declaration A declaration consists of four parts: an optional "specifier", a base
29
4248
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
3788
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): (R1) direct-declarator: identifier "(" declarator ")"
10
1894
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 a declarator......". The example used is char *pc where the declarator " *pc" tells us that " *pc is a character". Can one thus broadly say that a declarator is in fact equivalent to the base type?
0
8903
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8815
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8592
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7421
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4213
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4393
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2802
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2044
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1795
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.