[comp.sys.sgi] Outright bug in the SGI C compiler...

steve@vicom.com (Steve Maurer) (11/28/89)

	While trying to polish off the ends of a project, I ended
up having to do a work-around for a mutual design deficiency between
our product and the SGI compiler.   However, on the work around
itself, I found another, much less forgivable bug in the SGI
compiler; an outright violation of the C standard.

	While the compiler allows pointers to functions to be
assigned, it does not allow them to be compared.  It also doesn't
allow them to be cast to allow comparison.   The following example
illustrates the problem.  It was checked out on a number of other
C compilers (Sun being the main one), and it compiled and performs
flawlessly.   But not on the SGI.

- - - - - - - - - - - - - - - - - - - - - - - -

void foo(), bar();

main()
{
void (*pfn)();

pfn = foo;			/* SGI compiler allows this	*/

if ( pfn == foo )		/* but barfs on this		*/
	printf("Pfn calls foo\n");
else
	printf("Pfn calls bar\n");
}

void
foo()
{
}

void
bar()
{
}
- - - - - - - - - - - - - - - - - - - - - - - -

	My question is: does anybody know a work around for this flaw?
Is there a new release fix for it?   If that's the case, I need the
new stuff immediately, since the project I'm working on is already way
behind.

						Steve Maurer
						steve@vicom.com

steve@vicom.com (Steve Maurer) (11/28/89)

Steve Maurer:
>- - - - - - - - - - - - - - - - - - - - - - - -
>
>	My question is: does anybody know a work around for this flaw?
>Is there a new release fix for it?   If that's the case, I need the
>new stuff immediately, since the project I'm working on is already way
>behind.

    Never mind.  I found a work-around by declaring a dummy procedure
rk (for real kludge), which I pass the function pointer to, but declare
as an integer argument.   Gack.   Never thought I'd have to resort to
a pascal function pseudo-cast in a C program.

						Steve Maurer
						steve@vicom.com

davea@quasar.wpd.sgi.com (David B. Anderson) (11/29/89)

In article <1989Nov27.234730.25669@vicom.com> steve@vicom.COM (Steve Maurer) writes:
>
>
>	While trying to polish off the ends of a project, I ended
>up having to do a work-around for a mutual design deficiency between
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>our product and the SGI compiler.   However, on the work around
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	Please send e-mail on the original compiler problem. I'd
	like to know what it was so I can fix it.

>itself, I found another, much less forgivable bug in the SGI
>compiler; an outright violation of the C standard.
>
>	While the compiler allows pointers to functions to be
>assigned, it does not allow them to be compared.  It also doesn't
>allow them to be cast to allow comparison.   The following example
>illustrates the problem.  It was checked out on a number of other
>C compilers (Sun being the main one), and it compiled and performs
>flawlessly.   But not on the SGI.

Steve:

The problem is that void was not handled properly in released versions of
the c compiler.  Change the function return types to int and the problem
disappears.

In the next release (after 3.2) of IRIX void and void * are properly handled.

My aplogies for the inconvenience.

Regards,
[ David B. Anderson  Silicon Graphics  (415)335-1548  davea@sgi.com ]

mtoy@sgi.com (Michael Toy) (11/29/89)

I compiled and ran the example verbatim from your message,
and .... it works fine for me.  My guess is that you are running
an older release of IRIX.  Under 3.2, no such problem exists.

Michael Toy

mike@BRL.MIL (Mike Muuss) (11/30/89)

One workaround might be to create a union between the function pointer
and a long.  Assign into the pointer element, compare the long element.
Ugly, but it will get you going.  You can probably hide it with some
macros if you have to do it a lot.

	Best,
	 -Mike