This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Type casting problem


Thank you all for the help. It is most appreciated :)

_Kevin

--- Der Herr Hofrat <der.herr@hofr.at> wrote:
> > >
> > > int main(int argc, char *argv[])
> > > {
> > >     double  amount;
> > >     double  cost;
> > >     long    iamount;
> > >
> > >     cost = 0.06;
> > >     amount = cost * 100;
> > >     iamount = (long)(((double)cost) * 100);
> > >
> > >     printf("Amount %lf\n", amount);
> > >     printf("Integer Amount %ld\n", iamount);
> > >
> > >     return (0);
> > > }
> > >
> > > Here's the output:
> > >
> > > Amount 6.000000
> > > Integer Amount 5
>  >
> 
> -O2 is the solution 
> 
> note that this is not realy explicid typcasting
> related (that is implicid 
> casts do the same job) , so:
> 
>    iamount = cost * 100;
> 
> will do the same
> 
> hofrat


__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]