4D Rel3 BUG ALERT

Mike Muuss mike at BRL.MIL
Wed Sep 21 18:46:12 AEST 1988


This evening, I ran into the most horrid bug in the C Compiler on the
SGI 4-D machines, under Release 3.0 and 3.1alpha both. It all came about
from these messages:

ccom: Warning: ../h/vmath.h, line 53: inconsistent prototypes for function sqrt
                extern double sqrt();
      ------------------------------^ 

because my header file "vmath.h" wants to be certain that sqrt() has
been properly declared.  The entry from SGI's /usr/include/math.h is:

extern double cbrt(double), sqrt(double);

Not reading that carefully, I had originally assumed that this was the
ANSI way of doing things, and even though __STDC__ was not defined by
SGI, I changed vmath.h to read:

#ifndef sqrt
#       if defined(__STDC__) || \
        (defined(sgi) && defined(mips) && !defined(SGI4D_Rel2))
                 extern double sqrt(double _sqrt_arg_x);
#       else
                 extern double sqrt();
#       endif
#endif

This caused the error messages to go away, but gave me mysterious
errors in all my programs;  all of which pointed to a malloc()
problem.  Wrong.

What was happening was the extern sqrt() declaration gave every
subroutine IN THAT MODULE a free first argument (of type double), called
"_sqrt_arg_x".  This caused all the visibly declared arguments to
take on the value of their neighbor, and the last one got junk. Probably
the parser pushed the arg onto a list of args in some "global" block,
and never popped it off.

I would like to add in passing that SGI's "dbx" program was of no
help whatsoever, printing 5 invented numbers as the arguments to
the functions in the stack traceback ("where" command).
I had to resort to printf()s, printing the parameters sent,
and more printf()s printing the parameters received.

So, for the time being, my new version of vmath.h contains
this contortion:

#ifndef sqrt
	/* In case <math.h> has not been included, define sqrt() here */
#	if defined(__STDC__)
		extern double sqrt(double x);
#	else
#		if (defined(sgi) && defined(mips) && !defined(SGI4D_Rel2))
			/* What could SGI have been thinking of? */
			extern double sqrt(double);
#		else
			extern double sqrt();
#		endif
#	endif
#endif

This version (a) still silences the compiler, and (b) gives the subroutines
the right argument list.

SGI's graphics is great.  The 4-D GT is breath-taking.  When things
work, they work rapidly.  But, when is somebody going to show SGI how to
write software?  The single most often repeated phrase in our office
is "G** D**n SGI software!".

	Fuming,
	 -Mike



More information about the Comp.sys.sgi mailing list