typedef scope mess
David Keppel
keppel at pavepaws.berkeley.edu
Tue Jun 10 14:02:29 AEST 1986
In article <1003 at g.cs.cmu.edu> ckk at g.cs.cmu.edu (Chris Koenigsberg) writes:
>not in MY K&R!!
>
>tps at sdchem said the following program should be legal as it was from
>"K&R p.206":
>> typedef float distance;
>>
>> main()
>> {
>>
>> auto int distance;
>>
>> /*###8 [cc] unknown size%%%*/
>> /*###8 [cc] cannot recover from earlier errors: goodbye!%%%*/
>> /*###8 [cc] syntax error%%%*/
>> /*###8 [cc] warning: illegal combination of pointer and integer, op =%%%*/
>> distance = 1;
>> printf( "distance = %d\n", distance );
>> }
Well here's what's in my K&R (1978) pg 206:
KR
KR Remember also (section 8.5) that identifiers associated with
KR ordinary variables on the one hand and those associated with
KR structure and union members and tags on the other form two disjoint
KR classes which do not conflict. Members and tags follow the same
KR scope rules as other identifiers. typedef [sic] names are in the
KR same class as ordinary identifiers. They may be redeclared in inner
KR blocks, but an explicit type must be given in the inner declaration:
KR
KR typedef float distance;
KR ...
KR {
KR auto int distance;
KR ...
KR
KR The int must be present in the second declaration, or it would be
KR taken to be a declaration with no declarators and type
KR distance[dagger].
KR
KR -------
KR [dagger] It is agreed that the ice is thin here.
:-D avid K eppel ..!ucbvax!pavepaws!keppel
"Learning by Osmosis: Gospel in, Gospel out"
More information about the Comp.lang.c
mailing list