🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #41610

GCC 2.7.2 on Solaris 2.4 compiles wrong with -ansi !!

#41610
From: David C. M. Bilsby
Date: Wed, 28 Feb 1996 00:00
67 lines
2081 bytes
Hi,
	A collegue spotted the following problem and blaimed me as system
admin, however I think its gcc 2.7.2 under Solaris 2.4 thats at fault.

	If you compile the following code to calculate a simple pythagorus
triangle problem with :

	% gcc -o testprog testprog.c -lm   

then

	% gcc -ansi -o testprog testprog.c -lm 

you get 
	
	3.000000 4.000000 5.000000
and
	3.000000 4.000000 1074266112.000000

respectively, ie. wrong with -ansi flag.

If you add -Wall to the -ansi option things start to become clearer :

	% gcc -ansi testprog.c -o testprog -lm -Wall
	testprog.c:6: warning: return-type defaults to `int'
	testprog.c: In function `main':
	testprog.c:10: warning: implicit declaration of function `hypot'
	testprog.c:13: warning: control reaches end of non-void function

It shows that the hypot function is assumed to have int return value. However
it is defined correctly in the /usr/include/math.h header It is defined
within a strange #if preprocessor which means it is not included when gcc
compiles with either -ansi or not. Without the -ansi it does not seem
to matter too much. The include is :

[stuff]
#if __STDC__ - 0 == 0 && !defined(_POSIX_SOURCE) || defined(_XOPEN_SOURCE)
/*
 * SVID & X/Open
 */
extern double erf __P((double));
extern double erfc __P((double));
extern double gamma __P((double));
extern double hypot __P((double, double));
[more stuff]

	Hope this helps track the problem down.

		David.

[testprog.c]

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
 
main()
{ double x,y,a;
 
 x = 3.0; 
 y = 4.0;
 a = hypot(x,y);
 printf("%f %f %f\n",x,y,a);
 
}

[end testprog.c]
Technical Details
Message-ID: <4h16jm$631@signal.dra.hmg.gb>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,b65cdfcedc85c7d,start
X-Google-Attributes: gid11318c,public
From: bilsby@panther.dra.hmg.gb (David C. M. Bilsby)
Subject: GCC 2.7.2 on Solaris 2.4 compiles wrong with -ansi !!
Date: 1996/02/28
Message-ID: <4h16jm$631@signal.dra.hmg.gb>
X-Deja-AN: 141460416
organization: Defence Research Agency
newsgroups: gnu.gcc.help