avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Type casting from 32 bit to 64 bit ... doesnt seem to


From: intiha Ho gai
Subject: Re: [avr-gcc-list] Type casting from 32 bit to 64 bit ... doesnt seem to work
Date: Sat, 11 Jun 2005 21:52:21 -0700

hmm, So any comment as to why it might be happening to me? I am sure
there is something else that i am missing that affects this, but let
me give yout the exact code that i use, that is giving me incorrect
results so that you can help me more.


typedef struct regTblEntry {
int32_t x;
int32_t  y; 
}TblEntry;
TblEntry regTable[BEACONS_REQUIRED];

for (i=0; i< BEACONS_REQUIRED; i++){
                
        sumX +=  regTable[i].X;
        sumY +=  regTable[i].Y;
        
         printf( " %ld, %ld, \r\n ", regTable[i].X,regTable[i].Y);
         
        }


At the end when I print the sumX and sumY values, the are incorrect.

Thanks for all the help.

Regards
-Affan


On 6/10/05, Dmitry K. <address@hidden> wrote:
> On Saturday 11 June 2005 03:16, intiha Ho gai wrote:
> > Hi,
> > I dont know if this an avr-gcc issue, but it seems that if i am try to
> > typecast variables in an array of uint32_t to uint64_T as follows:
> > sumX += (uint64_t)array.x;
> > (where sumX is an uint64_t var, while array.x is uint32_t),
> > then this summation doesnt seem to work i.e. my summation values are
> > just totally incorrect.
> > however, when i change the type of array.x to be uint64_t and do no
> > typecasting (although the values of x are within the range of 32 bit)
> > the results are correct.
> > Any insight why this is so?
> 
> The next program run fine (avr-gcc 3.3.5):
> 
> #include <stdint.h>
> 
> volatile struct {
>     uint32_t x;
> } array = { 123456789 };
> 
> uint64_t main ()
> {
>     uint64_t sum = -123456789;
>     /* to clean `sum' fully, 64-bits operation is needed        */
>     sum += (uint64_t) array.x;
>     return sum;
> }
> 
> Dmitry.
> 
> 
> 
> _______________________________________________
> AVR-GCC-list mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]