Path: utzoo!attcan!uunet!mailrus!sharkey!amara!mcdaniel From: mcdaniel@adi.com (Tim McDaniel) Newsgroups: comp.std.c Subject: Re: Quick Question Message-ID: Date: 15 Aug 90 15:39:15 GMT References: <10136@pt.cs.cmu.edu> <880@mwtech.UUCP> Sender: news@adi.COM Organization: Applied Dynamics Int'l. Lines: 44 In-reply-to: martin@mwtech.UUCP's message of 8 Aug 90 20:16:11 GMT martin@mwtech.UUCP (Martin Weitzel) writes: You can ALLWAYS start with the name of the object (here: a), end with the type (here: int) and simply build your type description by concatenating what you encounter on your way "inside to out". So the first is the correct parsing. Because of this some people even prefer int const x; /* would read: x is a constant int */ over const int x; /* would read: x is an int constant */ Both have the same meaning in ANSI C - the first seems more "logical", but the second is (still) in more widespread use. I thought so too, until I read K&R2 more closely. In the example given above, "const" 'binds' to "int" rather than "x". So it differs from the treatment of "*" in declarations (the only prefix operator in declarations): int * ip, i; /* ip is pointer to int, i is int */ int const ci, ci2; /* ci is const int, ci2 IS ALSO CONST INT */ Of less importance, "const" and "volatile" are special; in the middle of a declaration, they can only appear immediately after a "*" token. int *p, (*p2), *(p3); /* all are pointers to int */ int * const cpi; /* cpi is const pointer to int */ int (* const cpi2); /* cpi2 is const pointer to int */ int *(const cpi3); /* illegal: syntax error */ So you can't just use the inside-out construction rules blindly here: you must remember that "const" is part of the type identifier, so I consider "int const" to be misleading. I think it would have been more consistent to treat "const" and "volatile" in declarations just like "*", as a prefix unary operator. It's now far too late. -- -- Tim McDaniel Internet: mcdaniel@adi.com UUCP: {uunet,sharkey}!amara!mcdaniel