#include<iostream> using namespace std; class Rational { int numerator; int denominator; public: int GetNum () { return numerator; } int GetDen () { return denominator; } void setNum (int numer) { numerator = numer; } void setDen (int den) { denominator = den; } int gcd (int i1, int i2) { if (i2 == 0) return i1; else return gcd (i2, i1 % i2); } public : Rational (float f) { int denom = 1; while (((int) f - f)!= 0) { f *= 10; denom *= 10; } int Gcd = gcd (int (f), denom); numerator = f / Gcd; cout <<numerator <<endl; denominator = denom / Gcd; cout<<"-----"<<endl; cout <<denominator <<endl; } }; int main (int argc, char **argv) { Rational r1 = Rational (.4537f); } ----------------------------------------- This runs successfully with: g++ without any optimization , but with -O or -02 or -03 the executable just hangs forever On Thu, 2006-02-23 at 10:56 +0100, Jerome Robert wrote: > Here is the faulty program (this kind of code is generated by > http://www.swig.org): > > /////////// Start /////////// > #include <stdio.h> > > int main(void) > { > long long a = 0x77777777L; > long long b = 0; > void ** aa=(void **)(void *)&a; > void ** ab=(void **)(void *)&b; > *ab = *aa; > printf("in: %llX, out: %llX\n", a, b); > return 0; > } > /////////// End /////////// > > The output for the following version is: > (Debian 1:3.3.6-12) g++ in: 77777777, out: 77777777 > (Debian 1:3.3.6-12) g++ -O1 in: 77777777, out: 77777777 > (Debian 1:3.3.6-12) g++ -O2 in: 77777777, out: 77777777 > (Debian 4.0.2-9) g++ in: 77777777, out: 77777777 > (Debian 4.0.2-9) g++ -O1 in: 77777777, out: 77777777 > (Debian 4.0.2-9) g++ -O2 in: 77777777, out: 0 > > So there is something wrong with g++ -O2 (Debian 4.0.2-9). Is this program wrong > or is this a bug ? > > Regards, > > Jerome -- Thanks and Regards Digvijoy Chatterjee Please Visit http://indra/LiMS and start your Linux Journey **************** CAUTION - Disclaimer ***************** This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely for the use of the addressee(s). If you are not the intended recipient, please notify the sender by e-mail and delete the original message. Further, you are not to copy, disclose, or distribute this e-mail or its contents to any other person and any such actions are unlawful. This e-mail may contain viruses. Infosys has taken every reasonable precaution to minimize this risk, but is not liable for any damage you may sustain as a result of any virus in this e-mail. You should carry out your own virus checks before opening the e-mail or attachment. Infosys reserves the right to monitor and review the content of all messages sent to or from this e-mail address. Messages sent to or from this e-mail address may be stored on the Infosys e-mail system. ***INFOSYS******** End of Disclaimer ********INFOSYS***