Article View: comp.std.c
Article #6173Is `char const *foo;' legal?
From: Ron Guilmette
Date: Wed, 10 Jan 1990 23:04
Date: Wed, 10 Jan 1990 23:04
38 lines
1722 bytes
1722 bytes
I have recently learned that the GNU C compiler accepts the following
declaration without complaint:
char const *foo;
It treats such a declaration as being identical to:
const char *foo;
Now I have looked at the draft ANSI standard, and I can find no examples
that look like `<typename> const *<variable-name>;'.
Due to the fact that the C declaration syntax is so complex, I don't
even want to try to think about the issue of whether or not such declarations
are syntactically legal.
So let me just ask the general question: "Are such declarations both
syntactically and semantically legal?"
Please excuse me if this question seems excessively naive. It is just
that I have never before seen any declarations of this form.
One other question. If this form of declaration *is* legal, then
does the standard contain any verbage which would clarify the type of
`bar' in the following example?
void foo (char const bar[])
{
}
GCC accepts this declaration, and it binds the `const' with lower `priority'
that the `[]'. Thus, the type of `bar' is taken as pointer to constant char.
I have found no basis in the standard for either this binding *or* for the
other alternative (i.e. binding the `const' more tightly than the `[]').
Did I miss something? Which binding is "correct"? Why?
// rfg
Technical Details
Message-ID:
<25ABBF93.9618@paris.ics.uci.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!jarthur!uci-ics!gatewayShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!jarthur!uci-ics!gateway From: rfg@paris.ics.uci.edu (Ron Guilmette) Newsgroups: comp.std.c Subject: Is `char const *foo;' legal? Message-ID: <25ABBF93.9618@paris.ics.uci.edu> Date: 10 Jan 90 23:04:51 GMT Organization: UC Irvine Department of ICS Lines: 38