Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!munnari.oz.au!bruce!monu0.cc.monash.edu.au!monu6!minyos.xx.rmit.oz.au!s900387 From: s900387@minyos.xx.rmit.oz.au (Craig Macbride) Newsgroups: comp.unix.aix Subject: Re: cc -O producing faulty code Message-ID: <1991Jun2.124226.17523@minyos.xx.rmit.oz.au> Date: 2 Jun 91 12:42:26 GMT References: <1991Jun1.065826.5526@minyos.xx.rmit.oz.au> <808@rufus.UUCP> Distribution: comp Organization: Royal Melbourne Institute of Technology, Melbourne, Australia Lines: 92 drake@drake.almaden.ibm.com writes: >How about posting an example, and the level of AIX you're running? Release 1, Version 3. An example follows, with test script and result. You will notice that I've put the optimised program's output through "cat -v" to make it at least keep to ASCII characters. :-) It seems very strange that code which occurs after the fprintf() statement seems to be causing the result of it to change. The full-sized program was, of course, using the variable new_usual_dom in output as well, but like all code which didn't affect the problem, I've removed it. -------------------------------program------------------------------------- #include #include #include char lga_name[100]; char usual_dom[100]; char line[1000]; char new_lga_name[100]; char new_usual_dom[100]; main(argc,argv) int argc; char **argv; { while (fgets(line,1000,stdin) != NULL) { memcpy(usual_dom,line+31,20); usual_dom[20] = '\0'; memcpy(lga_name,line+51,10); lga_name[10] = '\0'; if (strcmp(lga_name,"ELTHAM ")==0) strcpy(new_lga_name,"2640"); else if (strcmp(lga_name,"PRESTON ")==0) strcpy(new_lga_name,"6000"); else if (strcmp(lga_name,"WHIT/SEA ")==0) strcpy(new_lga_name,"8040"); else if (strcmp(lga_name,"D/VALLEY ")==0) strcpy(new_lga_name,"2280"); else if (strcmp(lga_name,"UNKNOWN ")==0) strcpy(new_lga_name,"9999"); else strcpy(new_lga_name,"0000"); fprintf(stdout, "'%s'\n", new_lga_name); #ifndef KILL3 if (strcmp(usual_dom,"it doesn't seem to ")==0) strcpy(new_usual_dom,"1"); else if (strcmp(usual_dom,"matter what this ")==0) strcpy(new_usual_dom,"2"); else if (strcmp(usual_dom,"text is exactly, nor")==0) strcpy(new_usual_dom,"3"); else if (strcmp(usual_dom,"matter that it is ")==0) strcpy(new_usual_dom,"4"); else if (strcmp(usual_dom,"_after_ the fprintf ")==0) strcpy(new_usual_dom,"5"); else if (strcmp(usual_dom,"... it still causes ")==0) strcpy(new_usual_dom,"6"); else if (strcmp(usual_dom,"the optimised output")==0) strcpy(new_usual_dom,"7"); else if (strcmp(usual_dom,"to be wrong... ")==0) strcpy(new_usual_dom,"7"); else if (strcmp(usual_dom," ")==0) strcpy(new_usual_dom,"7"); else if (strcmp(usual_dom,"xxxxxxxxxxxxxxx ")==0) strcpy(new_usual_dom,"7"); else if (strcmp(usual_dom,"OTHER ")==0) strcpy(new_usual_dom,"7"); else if (strcmp(usual_dom,"UNKNOWN ")==0) strcpy(new_usual_dom,"0"); else strcpy(new_usual_dom,"X"); #endif } exit(0); } -------------------------------script to test it--------------------------- echo Normal cc -o x x.c x < in echo Optimised cc -O -o xopt x.c xopt < in | cat -v echo Optimised with what should be irrelevant code removed cc -O -DKILL3 -o xopt2 x.c xopt2 < in -------------------------------output of test------------------------------ Normal '8040' '6000' Optimised ' ^ClD' ' ^Cl0' Optimised with what should be irrelevant code removed '8040' '6000' -- _--_|\ Craig Macbride / \ \_.--.*/ The above are simply my comments, not necessarily v the views of any other being or organisation.