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


> >
> > 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


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