Switch case common code

MKR mkr at mmm.UUCP
Fri Jun 20 04:31:26 AEST 1986


In article <134 at danews.UUCP> lvc at danews.UUCP (Larry Cipriani) writes:
>The 'best' I think that can be done is to do something like:
>
>	switch (switch_variable)
>	{
>	case a: ...
>		...
>		goto common;
>		break;
>
>	case b: ...
>		...
>	common:	common_code_for_a_and_b
>		break;
>
>	case c: ...
>		...
>		break;
>	}
>
>Larry Cipriani		AT&T Network Systems

	Why not:

int common_stuff()
{
	blahblahblah
}

main()
{
...
	switch (thnad) {
	case A:
		do the A stuff;
		common_stuff();
		break;
	case B:
		do the B stuff;
		common_stuff();
		break;
	case C:
		do the C stuff;
		break;
	}

I thought that's what functions were for.

	--MKR



More information about the Comp.lang.c mailing list