chittamu@umvlsi.ecs.umass.edu (Satish Kumar .C) (02/27/90)
The grammar in K & R 2nd edition gives the rule for Declaration Specifiers as follows. Declaration_Specifiers : Storage_Class_Specifier | Type_Specifier | Type_Qualifier | Storage_Class_Specifier Declaration_Specifiers | Type_Specifier Declaration_Specifiers | Type_Qualifier Declaration_Specifiers ; Obviously this means we can have declarations of the sort register const int const register int int register const etc. I was always under the impression that the rule had to be Declaration_Specifiers : Type_Qualifier Storage_Class_Specifier Type_Specifier Am I mistaken? Is my interpretation of K & R's grammar correct? Or is there some other reason for it being that way? Any help would be greatly appreciated. Thanks, -- -Satish. chittamu@cs.umass.edu -- The Theory of Objectivity: E = MC++
karl@haddock.ima.isc.com (Karl Heuer) (02/27/90)
In article <750@umvlsi.ecs.umass.edu> chittamu@umvlsi (Satish Kumar .C) writes: >The grammar in K & R 2 [implies] we can have declarations of the sort > register const int > const register int > int register const >etc. Right. Mostly for backward compatibility with pre-ANSI C. >I was always under the impression that the rule had to be >Declaration_Specifiers : Type_Qualifier Storage_Class_Specifier Type_Specifier No, in fact the storage class should be the first word (all other orderings are obsolescent). Nothing is said about the relative ordering of qualifier and type specifier, but because of the interaction between qualifiers and `*', it can be argued that the logical ordering is SCS TS TQ: extern int const x; /* x is a constant int */ extern int const * p; /* p is a pointer to a constant int */ extern int * const p; /* p is a constant pointer to an int */ This is my preferred ordering. Opinions will differ. Karl W. Z. Heuer (karl@ima.ima.isc.com or harvard!ima!karl), The Walking Lint
gary@hpavla.AVO.HP.COM (Gary Jackoway) (02/27/90)
>>I was always under the impression that the rule had to be >>Declaration_Specifiers : Type_Qualifier Storage_Class_Specifier Type_Specifier > No, in fact the storage class should be the first word (all other orderings > are obsolescent). Nothing is said about the relative ordering of qualifier > and type specifier, but because of the interaction between qualifiers and `*', > it can be argued that the logical ordering is SCS TS TQ: > extern int const x; /* x is a constant int */ > extern int const * p; /* p is a pointer to a constant int */ > extern int * const p; /* p is a constant pointer to an int */ > This is my preferred ordering. Opinions will differ. ---------- Too bad you can't do this in MSC. The "near" specifier has to be immediately before the function definiton. This leads to yukky looking defintions like: static int * near foo(); Sigh. Gary Jackoway