[net.unix] Possible C Compiler Bug?

john@wvlpdp (06/06/86)

	I am using Ultrix-11 Version 2.0 on a PDP 11/73
	and ran into a problem when trying to compile some code.
	After much tearing of hair and grinding of teeth the problem boiled down
	to the following:

This compiles:

main()
{
	A lot of code here;
	goto here;
		
	More code here;

here:
	;
}

This will not:
main()
{
	A lot of code here;
	goto here;
		
	More code here;

here:
}
	Is this a compiler bug?




John A. Ebersold 				World Video Library
ihnp4!convex!ctvax!trsvax!hal6000!wvlpdp!john	2747 Airport Freeway
						Fort Worth, Texas 76111
						(817)-831-3811

fnf@unisoft.UUCP (Fred Fish) (06/10/86)

In article <6200004@wvlpdp> john@wvlpdp writes:
>This compiles:
	[deleted]
>here:
>	;
>}
>
>This will not:
	[deleted]
>here:
>}
>	Is this a compiler bug?

No, though some broken compilers may accept it.  From K&R page 204:

	Any *statement* may be preceded by label prefixes..

	The null statement has the form

		;

	A null statement is useful to carry a label just before the
	} of a compound statement...

Bottom line is that you must "attach" the label to a statement, even if
only the null statement.

-Fred

===========================================================================
Fred Fish    UniSoft Systems Inc, 739 Allston Way, Berkeley, CA  94710  USA
{ucbvax,lll-lcc}!unisoft!fnf	(415) 644 1230 		TWX 11 910 366-2145
===========================================================================

henry@mit-trillian.MIT.EDU (Henry Mensch) (06/10/86)

In article <6200004@wvlpdp> john@wvlpdp writes:
>
>This compiles:
>main()
>{
>	A lot of code here;
>	goto here;
>	More code here;
>here:
>	;
>}
>
>This will not:
>main()
>{
>	A lot of code here;
>	goto here;
>		
>
>here:
>}
>
>	Is this a compiler bug?

	This is *not* a compiler bug -- Kernighan & Rtichie states
that "Any statement may be preceded by label prefixes of the form 

	identifier:

which serve to declare the identifier as a label. . . ."  The example
that you show which does *not* compile does *not* have a statement
after the label, and the label is misplaced.  

	Your first example has a null statement after the label. This
works fine, since there is indeed a statement after the label.

-- 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Henry Mensch     |    Technical Writer     | MIT/Project Athena
henry@athena.mit.edu              ..!mit-eddie!mit-athena!henry