Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

int const * p;

9 views
Skip to first unread message

Joachim Sprave

unread,
Sep 1, 1992, 11:12:08 AM9/1/92
to
Could anybody look in the standard, if

int const * p;

is allowed ?

GCC treats it as

const int * p;

SUN's acc gives an error.

//////\\
/ \
_| _ _ |_
|.|-(.)-(.)+.|
\| J |/
\ --- /
\ /
"####"
Joachim

Karl Heuer

unread,
Sep 1, 1992, 3:35:29 PM9/1/92
to
In article <180188...@fbi-news.Informatik.Uni-Dortmund.DE> spr...@gonzo.informatik.uni-dortmund.de (Joachim Sprave) writes:
>Could anybody look in the standard, if int const * p; is allowed?
>SUN's acc gives an error.

Yes, it is legal. A compiler that rejects it is not Standard-conforming.

02-Sep-1992 0949

unread,
Sep 1, 1992, 8:50:05 PM9/1/92
to
In article <180188...@fbi-news.Informatik.Uni-Dortmund.DE> spr...@gonzo.informatik.uni-dortmund.de (Joachim Sprave) writes:
>Could anybody look in the standard, if int const * p; is allowed ?

Yes, it would be very easy for you to look that up :-)
(Some parts of the standard are obscure, but not this one.)

>GCC treats it as const int * p;

That is correct.

>[Other compiler] gives an error.

If the vendor claims that that compiler is ANSI or ISO conforming, and if
you paid money for it, then get a refund. [Personal opinion only.]
--
Norman Diamond dia...@jit081.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.
"Yeah -- bad wiring. That was probably it. Very bad."

Joachim Sprave

unread,
Sep 2, 1992, 4:27:02 AM9/2/92
to
Sorry,

I apologize to SUN, Jutta you're right. The fact is, in my test
program I jumped to the wrong line. So

int const * p;

is accepted by acc and gcc. The error message occured in the line

const int const *q;

which IMO is incorrect, or at least useless.
acc reports: "constp.c", line 4: invalid type combination
gcc reports: constp.c:4: warning: duplicate `const'

Thanks to all who answered

John F. Woods

unread,
Sep 2, 1992, 12:02:53 PM9/2/92
to
spr...@gonzo.informatik.uni-dortmund.de (Joachim Sprave) writes:
>I apologize to SUN, Jutta you're right. The fact is, in my test
>program I jumped to the wrong line. So
> int const * p;
>is accepted by acc and gcc. The error message occured in the line
> const int const *q;
>which IMO is incorrect, or at least useless.

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

Your opinion is fact, it is incorrect.

Peter van der Linden

unread,
Sep 2, 1992, 1:34:15 PM9/2/92
to
John omitted only the reference to the manual, namely
section 3.5.3 "Type Qualifiers". It's not clear why a
meaningful construct, like a constant pointer to a constant value
is precluded.

However Joachim, I believe your appearance, if not your const problems,
could be improved by parting your hair on the other side, switching to
contact lenses and smiling. You would then look like this:

//\\\\\\

/ \
_| _ _ |_

|.| o o | }
\| \ |/
\ \ / /
\ ~ /
"####"
Joachim V2.0

--
lin...@eng.sun.com|| P. van der Linden and his uncustomary theories.
Go Giants!! Don't || When solving a "panic" you must first ask yourself what you
stop at Florida...|| were doing that could possibly frighten an operating system

John F. Woods

unread,
Sep 2, 1992, 3:09:25 PM9/2/92
to
lin...@positive.Eng.Sun.COM (Peter van der Linden) writes:
>John omitted only the reference to the manual, namely
>section 3.5.3 "Type Qualifiers". It's not clear why a
>meaningful construct, like a constant pointer to a constant value
>is precluded.

That construct isn't precluded;

const int * const a;

is OK. That declaration has two separate qualifier lists: one associated with
the type (int *) and one associated with the variable, essentially separated
by the *.

Paul Eggert

unread,
Sep 3, 1992, 12:28:01 AM9/3/92
to
j...@ksr.com (John F. Woods) writes:

> const int * const a;

>is OK.

Yes, but it's terribly confusing.
For consistency, you should always put `const'
_after_ the type that it modifies. Just like `*'.
So the declaration should be:

int const * const a;

It's too bad that common usage has this backwards.
Even the standard's examples are backwards.

0 new messages