[comp.bugs.4bsd] C compiler bug in Sun OS 3.0

fnf@mcdsun.UUCP (Fred Fish) (11/15/86)

[Is there a sun specific newsgroup under the new usenet organization, other
 than mod.computers.sun?]

/*
 *  DESCRIPTION
 *
 *	The C compiler has a bug with use of the comma operator in
 *	return expressions.
 *
 *  SUN OS REVISION
 *
 *	3.0 SUNBIN DOMESTIC 68020
 *	Part Number: 700-1114-05 Rev. A
 *
 *  COMMENTS
 *
 *	From K&R, pages 58-59:
 *
 *		"A pair of expressions separated by a comma is evaluated
 *		 left to right, and the type and value of the result are
 *		 the type and value of the right operand."
 *
 *	This bug has apparently been fixed in 3.2.
 *
 */

#include <stdio.h>

main ()
{
    int value;

    value = nobug ();
    printf ("nobug() returns %d, %#x, %#o\n", value, value, value);
    value = bug ();
    printf ("bug() returns %d, %#x, %#o\n", value, value, value);
    value = bugworkaround ();
    printf ("bugworkaround() returns %d, %#x, %#o\n", value, value, value);
}

int nobug () 
{
    return (0202);
}

int bug () 
{
    return (4, 0202);
}


int bugworkaround () 
{
    return (4, (int)0202);
}
-- 
===========================================================================
Fred Fish  Motorola Computer Division, 3013 S 52nd St, Tempe, Az 85282  USA
{mcdsun,well}!fnf    (602) 438-5976
===========================================================================