Message-ID: From: "EFT.Eric Devolder" To: djgpp AT delorie DOT com Subject: Program goes wrong when optimized under gcc 2.8 Date: Mon, 28 Sep 1998 11:24:28 +0200 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="---- =_NextPart_000_01BDEAD2.8EECFE90" Precedence: bulk This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------ =_NextPart_000_01BDEAD2.8EECFE90 Content-Type: text/plain > Hello, > > I'm written a little utility that takes a list of numbers, and > reformat the output following some rules. > I'm using gcc 2.8.1, with djgpp 2.01. > > ( >> gcc -v > Reading specs from e:/djgpp/lib/gcc-lib/djgpp\2.81\specs > gcc version 2.8.1 ) > > Everything works ok. > > I got the following trouble: > > When I compile the program like this: gcc -o hot2std.exe hot2std.c > it works perfeclty. > If I try to compile with optimization (gcc -O[1,2 or 3] -o hot2std.exe > hot2std.c), I get strange outputs, compared to those of the debug > version. > > Is is a bug in the compilator ? Did I forgot somehting ? > > > I've joined the source and an example to pass as argeument to the > file, so you can have a try to check what's happening. > > Thank you for the help, > > Regards, and enjoy djgpp. > > > Eric DEVOLDER > (look in to get my reply adress) > > ------ =_NextPart_000_01BDEAD2.8EECFE90 Content-Type: application/octet-stream; name="hot2std.c" Content-Disposition: attachment; filename="hot2std.c" #include #include #include #include void process_header(long *total, long *hash); void process_core(FILE *fp, long *total, long *hash); void process_tailer(long total, long hash); int main(int argc, char **argv) { FILE *fp = fopen(argv[1], "r"); if(fp) { long total, hash; process_header(&total, &hash); process_core(fp, &total, &hash); process_tailer(total,hash); fclose(fp); } return EXIT_SUCCESS; } void process_header(long *total, long *hash) { struct date *now; getdate(now); fprintf(stdout, "00007%02.2d%02.2d%02.2d REF%02.2d%02.2d%02.2d \n", now->da_year % 100, now->da_mon, now->da_day, now->da_year % 100, now->da_mon, now->da_day); *hash = *total = 0; } void process_core(FILE *fp, long *total, long *hash) { char buffer[256], *scan; char temp[32]; int i; while(fgets(buffer,256,fp)) { scan = strtok(buffer," \n\r\t"); if(scan) { (*total)++; sprintf(temp,"0002%06.6ldA%019.19s \n", *total, scan); fprintf(stdout,"%s",temp); for(i=22;i<30;i++) *hash += temp[i]-'0'; *hash %= 1000000L; /* from 000000 to 999999 */ } } } void process_tailer(long total, long hash) { fprintf(stdout,"0009%06.6ld000000%06.6ld \n", total, hash); } ------ =_NextPart_000_01BDEAD2.8EECFE90 Content-Type: application/octet-stream; name="raw" Content-Disposition: attachment; filename="raw" 829675487453075 037752318061804891 103049328881547 99033081585345690 625091268786167 72254112224180717 737000202010339 135586157629633 70696602637605 34493563326108498 631400339051271285 0847432064640 92687216086968 8560954324697 52572471609315 39642916691552761 06917489553482 01001852559639552 22466415178143 254045538706270 45180185353631 1143343523522 71813545676732 92591863965707646 816954815096585845 1221594201987 141046321294458512 5096357855376543 1323983593371379 404870752411233 364385320233487835 36022940036109 2126749725038852 5581532741171405 0468092296925996 70366121293795980 2295754100949 851619230970423632 5920505840715752 5571190252486 8519192501541830 94714539147926781 963248435104076733 76441608732721 600458764907814140 1795959219620200 40558722950280 679751659043272311 86584336709977 396063159512811754 ------ =_NextPart_000_01BDEAD2.8EECFE90--