To: djgpp AT delorie DOT com Subject: Program miscompiled by GCC From: ilari DOT liusvaara AT purkki DOT mbnet DOT fi (Ilari Liusvaara) Message-ID: <00CF54B.00640E1F47.uuout@purkki.mbnet.fi> Date: Sun, 22 Jul 00 22:35:00 +0200 Organization: MBnet - MikroBitti MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Mailreader: PCBoard v15.3 X-Aliaser: MBnet GuruX v2.18 X-Mailer: PCBoard/UUOUT v1.30 X-ESMTP-Daemon: KSP-Mail v3.4R (Jul 23 1997) Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from QUOTED-PRINTABLE to 8bit by delorie.com id KAA09470 Reply-To: djgpp AT delorie DOT com I have a problem with GCC and most likely it is a bug: When I compile this program with -ansi, GCC 2.7.2.1 generates program that bombs and GCC 2.9.5.2 generates program that display resluts that do not make sense. The comments and messages are in finnish and I don't bother to translate them. I have marked the line that generates instructions that bomb the program when compiled with GCC 2.7.2.1 (at least SYMIFY tells that it is that line.) When I compile without -ansi, program works just fine. It seems thet misbehaving program generated by GCC 2.9.5.2 is compiled seriously wrong. As I investigated problem further, I got strong proof that the problem is indeed in the C compiler. Comparing assembler outputs revealed that there were two (2.9.5.1) or three (2.7.2.1) extra assembler commands in file generated by GCC with -ansi parameter. Removing them gives program that works. The miscompiled part is from function kysy(...). I have marked this problematic line too. And by the way, I haven't subscribed to Djgpp mailing list. Source code of troublematic program: #include "stdio.h" #include "stdlib.h" #include "math.h" #ifdef __GNUC__ #ifdef __GNUG__ extern "C" { /*M,,rittele 3 systeemifunktiota tyhjiksi*/ #endif char ** __crt0_glob_function(char* _argument){return 0;} void __crt0_load_environment_file(char* _app_name){;} void __crt0_setup_arguments(){;} #ifdef __GNUG__ } #endif #endif #define Tnopeus_x (nopeus_x+tuuli) /*Nopeus tuulen suhteen*/ long double kysy(const char* kysymys); long double kysy(const char* kysymys) { char buf[255]; /*V,liaikaispuskuri*/ printf("%s",kysymys); fflush(stdout); /*Tulosta kysymys*/ gets(buf); /*ota vastaus*/ /***********************************************************************/ /**/return _atold(buf); /*<--THIS LINE IS MISCOMPILED!!!! */ /***********************************************************************/ } int main() { long double massa,nopeus,kulma,vastus,tuuli,korkeus; /*Parametreja*/ long double sij_x ikan komponentit*/ long double nopeus_x,nopeus_y; /*Nopeuden komponentit*/ long double aika ika*/ long double askel001; /*aika-askel numeerisessa ratkaisussa.*/ long double vasen semmaisin x-koordinatti.*/ long double oikeaimmainen x-koordinatti.*/ long double huippu inatti.*/ long double kiihtyvyys˜0655; /*painovoiman kiihtyvyys.*/ massa nopeus kulma vastus tuuli korkeus printf("Venaa hetki...\n"); huippu.*/ nopeus_x nopeus_y sij_y while(sij_y> */ { /*Alustetaan muuttujat*/ long double voima_x _y long double neliovauhti long double vauhti long double f_magnitudi aika+®l; /*P,ivitet,,n joitakin arvoja*/ /***********************************************************************/ /**/ sij_x+/***********************************************************************/ sij_y+ if(vauhti!ttei vain vauhti ole 0*/ { long double f_kerroin_x long double f_kerroin_y voima_x+þrroin_x*f_magnitudi; /*Lasketaan lopullinen*/ voima_y+þrroin_y*f_magnitudi; /*Voima*/ } nopeus_x+®l*voima_x/massa; /*Lasketaan voiman vai-*/ nopeus_y+®l*voima_y/massa; /*kutus*/ if(sij_xoikea) oikea if(sij_y>huippu) huippu } /*Silmukka loppuu*/ printf("Tulokset:\n"); /*Tulostetaan tulos.*/ printf("Lakikorkeus:%Gm\n",(double)huippu); printf("Kantama:%Gm\n",(double)sij_x); printf("Lentoaika:%Gs:\n",(double)aika); printf("Iskunopeus:%Gm/s:\n",(double)sqrt(nopeus_x*nopeus_x+nopeus_y*nopeus_y)) ; printf("Iskunopeus (x-komponentti):%Gm/s:\n",fabs((double)nopeus_x)); printf("Iskunopeus (y-komponentti):%Gm/s:\n",fabs((double)nopeus_y)); return 0; }