Is `char const *foo;' legal?
Ron Guilmette
rfg at paris.ics.uci.edu
Thu Jan 11 10:04:51 AEST 1990
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
More information about the Comp.std.c
mailing list