473,398 Members | 2,389 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,398 software developers and data experts.

const question

This may seem a little odd but I have a few simple questions. Basically, I'm
writing a really simple parser which understands C type declarations - the
only reason being, so that I understand C better. So here goes:

/* does this imply 'const int' ?? */
const c = 0;

/* is this legal C? it's allowed by my 'real' C compiler but I'm not sure */
const const const int c = 0;

/* same for this??? */
unsigned unsigned unsigned int u = 0;

thanks,
James

Nov 1 '06 #1
13 1674
In article <Xd********************@pipex.net>,
James Brown <no*@home.netwrote:
>/* is this legal C? it's allowed by my 'real' C compiler but I'm not sure */
const const const int c = 0;
C89 3.5.3 Type Qualifiers

The same type qualifier shall not appear more than once in
the same specifier list or qualifer list, either directly or
via one or more typedefs.
--
Programming is what happens while you're busy making other plans.
Nov 1 '06 #2
"Walter Roberson" <ro******@ibd.nrc-cnrc.gc.cawrote in message
news:ei**********@canopus.cc.umanitoba.ca...
In article <Xd********************@pipex.net>,
James Brown <no*@home.netwrote:
>>/* is this legal C? it's allowed by my 'real' C compiler but I'm not sure
*/
const const const int c = 0;

C89 3.5.3 Type Qualifiers

The same type qualifier shall not appear more than once in
the same specifier list or qualifer list, either directly or
via one or more typedefs.
--
ok thanks for clearing that one up....so if I'm understanding the above
paragraph correctly, the following is therefore invalid:

typedef const int cint;

const cint c; /* invalid as per C89 3.5.3 */

thanks,
James
Nov 1 '06 #3
2006-11-01 <Xd********************@pipex.net>,
James Brown wrote:
This may seem a little odd but I have a few simple questions. Basically, I'm
writing a really simple parser which understands C type declarations - the
only reason being, so that I understand C better. So here goes:

/* does this imply 'const int' ?? */
const c = 0;
This one wasn't answered. I believe the answer is yes for c89, no for
c99. 'int' is rarely strictly necessary for c89, actually, in that you
can usually write your program without it (but why would you want to?)
Nov 1 '06 #4
Jordan Abel wrote:
2006-11-01 <Xd********************@pipex.net>,
James Brown wrote:
>>This may seem a little odd but I have a few simple questions. Basically, I'm
writing a really simple parser which understands C type declarations - the
only reason being, so that I understand C better. So here goes:

/* does this imply 'const int' ?? */
const c = 0;


This one wasn't answered. I believe the answer is yes for c89, no for
c99. 'int' is rarely strictly necessary for c89, actually, in that you
can usually write your program without it (but why would you want to?)
s/int/const/ ?

--
Ian Collins.
Nov 1 '06 #5
Ian Collins <ia******@hotmail.comwrites:
Jordan Abel wrote:
>2006-11-01 <Xd********************@pipex.net>,
James Brown wrote:
>>>This may seem a little odd but I have a few simple
questions. Basically, I'm writing a really simple parser which
understands C type declarations - the only reason being, so that I
understand C better. So here goes:

/* does this imply 'const int' ?? */
const c = 0;


This one wasn't answered. I believe the answer is yes for c89, no for
c99. 'int' is rarely strictly necessary for c89, actually, in that you
can usually write your program without it (but why would you want to?)

s/int/const/ ?
No, I think Jordan's point is that C89 supports "implicit int", but
C99 doesn't.

I *think* it's true that any legal C89/C90 program can be re-written
as an equivalent program that doesn't use the "int" keyword, but I
don't care enough to verify it.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 1 '06 #6
Keith Thompson wrote:
Ian Collins <ia******@hotmail.comwrites:
>>Jordan Abel wrote:
>>>2006-11-01 <Xd********************@pipex.net>,
James Brown wrote:
This may seem a little odd but I have a few simple
questions. Basically, I'm writing a really simple parser which
understands C type declarations - the only reason being, so that I
understand C better. So here goes:

/* does this imply 'const int' ?? */
const c = 0;
This one wasn't answered. I believe the answer is yes for c89, no for
c99. 'int' is rarely strictly necessary for c89, actually, in that you
can usually write your program without it (but why would you want to?)

s/int/const/ ?


No, I think Jordan's point is that C89 supports "implicit int", but
C99 doesn't.

I *think* it's true that any legal C89/C90 program can be re-written
as an equivalent program that doesn't use the "int" keyword, but I
don't care enough to verify it.
Good point, it just wouldn't occur to me to use "implicit int".

--
Ian Collins.
Nov 1 '06 #7
James Brown:
>C89 3.5.3 Type Qualifiers

The same type qualifier shall not appear more than once in
the same specifier list or qualifer list, either directly or
via one or more typedefs.

That's bullshit about the typedef's! Why is the Standard so?

(It's fine in C++.)

--

Frederick Gotham
Nov 1 '06 #8
In article <nv*******************@news.indigo.ie>,
Frederick Gotham <fg*******@SPAM.comwrote:
>James Brown {included material that I quoted from the C89 standard}
>>C89 3.5.3 Type Qualifiers
>> The same type qualifier shall not appear more than once in
the same specifier list or qualifer list, either directly or
via one or more typedefs.
>That's bullshit about the typedef's! Why is the Standard so?
If your typedef is so transparent that you don't already know the
attribute you would qualify with, then when you qualify it
you run the risk of logical contradiction. If you already know
enough about the typedef to know there will be no logical contradiction
then you already know whether the attribute would be redundant or not.

--
All is vanity. -- Ecclesiastes
Nov 1 '06 #9
Walter Roberson:
>>That's bullshit about the typedef's! Why is the Standard so?

If your typedef is so transparent that you don't already know the
attribute you would qualify with, then when you qualify it
you run the risk of logical contradiction. If you already know
enough about the typedef to know there will be no logical contradiction
then you already know whether the attribute would be redundant or not.

Because C doesn't have templates, there would be no need to allow multiple
consts via typedef's.

--

Frederick Gotham
Nov 2 '06 #10
2006-11-01 <ln************@nuthaus.mib.org>,
Keith Thompson wrote:
Ian Collins <ia******@hotmail.comwrites:
>Jordan Abel wrote:
>>2006-11-01 <Xd********************@pipex.net>,
James Brown wrote:

This may seem a little odd but I have a few simple
questions. Basically, I'm writing a really simple parser which
understands C type declarations - the only reason being, so that I
understand C better. So here goes:

/* does this imply 'const int' ?? */
const c = 0;
This one wasn't answered. I believe the answer is yes for c89, no for
c99. 'int' is rarely strictly necessary for c89, actually, in that you
can usually write your program without it (but why would you want to?)

s/int/const/ ?

No, I think Jordan's point is that C89 supports "implicit int", but
C99 doesn't.

I *think* it's true that any legal C89/C90 program can be re-written
as an equivalent program that doesn't use the "int" keyword, but I
don't care enough to verify it.
There are cases where you can't do it if you want prototypes. And cases
where you need prototypes to be equivalent. Other than that, I think
you're probably right. If you don't want binary-compatibility... well,
is it possible anymore to declare a variadic function without
prototypes?

eh - well, int wasn't necessary in K&R as far as I can see.
Nov 2 '06 #11
Jordan Abel <ra****@random.yi.orgwrites:
2006-11-01 <ln************@nuthaus.mib.org>,
Keith Thompson wrote:
[...]
>I *think* it's true that any legal C89/C90 program can be re-written
as an equivalent program that doesn't use the "int" keyword, but I
don't care enough to verify it.

There are cases where you can't do it if you want prototypes. And cases
where you need prototypes to be equivalent. Other than that, I think
you're probably right. If you don't want binary-compatibility... well,
is it possible anymore to declare a variadic function without
prototypes?

eh - well, int wasn't necessary in K&R as far as I can see.
I don't think the "int" keyword is necessary even for prototypes.
Even in C99, the type usually referred to as "int" can be called
"signed".

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 2 '06 #12
Frederick Gotham wrote:
James Brown:
C89 3.5.3 Type Qualifiers

The same type qualifier shall not appear more than once in
the same specifier list or qualifer list, either directly or
via one or more typedefs.

That's bullshit about the typedef's! Why is the Standard so?

(It's fine in C++.)
can't you make your point in a more civil fashion?
--
Nick Keighley

Nov 2 '06 #13
Frederick Gotham wrote:
Walter Roberson:
>>That's bullshit about the typedef's! Why is the Standard so?
If your typedef is so transparent that you don't already know the
attribute you would qualify with, then when you qualify it
you run the risk of logical contradiction. If you already know
enough about the typedef to know there will be no logical contradiction
then you already know whether the attribute would be redundant or not.


Because C doesn't have templates, there would be no need to allow multiple
consts via typedef's.
Oh gods, please no. If templating ever comes to C, please oh please let
it be an unrequired extension of some sort.
Nov 2 '06 #14

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

Similar topics

15
by: Wolfram Humann | last post by:
Hi, please don't be too harsh if I made stupid errors creating this simple example from my more complex case. Suppose I have a class like this: class BOOK { const string title;
17
by: cheeser | last post by:
Hello all, Please see the question in the code below... Thanks! Dave #include <iostream>
5
by: Bolin | last post by:
Hi all, A question about smart pointers of constant objects. The problem is to convert from Ptr<T> to Ptr<const T>. I have look up and seen some answers to this question, but I guess I am too...
12
by: Christof Krueger | last post by:
Hello, I'm quite new to C++ so maybe there's something I miss. I write a simple board game. It has a board class. This class has a method that returns the count of pieces a player has on the...
2
by: Rouben Rostamian | last post by:
The main() function in the following code defines an m by n matrix, assigns value(s) to its elements, then passes the matrix to function foo(). For whatever it's worth, I have declared foo() so...
8
by: Michael Safyan | last post by:
Dear members of comp.lang.c++, I am a little bit confused about the differences between constant references and values. I understand that it is faster to use a constant reference ("const T&") than...
42
by: S S | last post by:
Hi Everyone I have const char *p = "Hello"; So, here memory is not allocated by C++ compiler for p and hence I cannot access p to modify the contents to "Kello" p = 'K'; // error at runtime
14
by: Tim H | last post by:
I understand the semantics of why this works the way it does. But I wonder if there's a reason for the behaviore at the line marked "QUESTION". I figured if there is an answer, someone here knows...
29
by: Rohit kumar Chandel | last post by:
Hi all, I have a doubt in const keyword. My understanding says that a variable declared const can not be modified by the module it is defined in. Then consider the following code segment:...
10
by: Stephen Howe | last post by:
Hi Just going over some grey areas in my knowledge in C++: 1) If I have const int SomeConst = 1; in a header file, it is global, and it is included in multiple translations units, but it...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
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,...
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.