typedef scope mess

Dan Jones jsisi at trwrb.UUCP
Wed Jun 11 23:00:32 AEST 1986


In article <1003 at g.cs.cmu.edu> ckk at g.cs.cmu.edu (Chris Koenigsberg) writes:
>Keywords:not in MY K&R!!

This is in reference to the note by tps at sdchem about the code fragment found on 
page 206 of K & R.  It is there in App. A of my volume (ISBN 0-13-110163-3,
1978), *BUT* it is flagged with a footnote which reads:
    "It is agreed that the ice is thin here."
The footnote refers to the requirement of "auto int distance" rather than
"auto distance" to avoid confusing the declaration syntax, but it is clear
than the same scoping issue must have been in the back of someone's mind.

And now for something completely different ...
I tried the code here using the Green Hills C compiler and it handled the
scoping issue 'correctly'.  The pcc based UniSoft compiler muffed it exactly
as reported by tps at sdchem.  Thus, I would suggest being very careful since
you never know what compiler your code may see next.  Not only that, but it
is just plain bad design to overload typedefs, depending on scoping to save
the functionality of the code.  [Couldn't resist my two cents worth.]

	Dan Jones
		...!trwrb!jcc-one!djones

Here is the code fragment for those who may have missed it:
	typedef float	distance;

	main()
	{
		auto int	distance;
		distance =	1;
		printf( "distance = %d\n", distance );
	}



More information about the Comp.lang.c mailing list