Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!think!paperboy!meissner From: meissner@osf.org (Michael Meissner) Newsgroups: comp.std.c Subject: Re: Is `char const *foo;' legal? Message-ID: Date: 11 Jan 90 15:41:48 GMT References: <25ABBF93.9618@paris.ics.uci.edu> Sender: news@OSF.ORG Organization: Open Software Foundation Lines: 53 In-reply-to: rfg@paris.ics.uci.edu's message of 10 Jan 90 23:04:51 GMT In article <25ABBF93.9618@paris.ics.uci.edu> rfg@paris.ics.uci.edu (Ron Guilmette) writes: | 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 ` const *;'. | | 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?" Yes. The reason you didn't see syntax for: const *; is because it would lead to a reduce/reduce conflict, since const and volatile are typenames. | 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? In the above example, const binds with char (ie, lower priority), since the typename goes to the innermost part of the declaration. -- Michael Meissner email: meissner@osf.org phone: 617-621-8861 Open Software Foundation, 11 Cambridge Center, Cambridge, MA Catproof is an oxymoron, Childproof is nearly so