This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Is this portable code?

Does this code port well to a 16 bit machine (written on 32 bit machine)?

int code     = 0x10 ;
int marker   = 0x20 ;
unsigned long frame;

int main(void)
{
        frame = (unsigned short)~marker<<11 | (unsigned short)code<<5 | marker;
        frame|= (unsigned long)~code<<16 ;

Parents
  • I see that

    frame = (unsigned short)~marker<<11
    

    gives 0x7FEF800 on a 32 bitter, but why does not the cast remove the higher word? I see the compiler using the BIC instruction (with 0x1F0000) rather than shifts to perform the cast.
    You are right in the end I get 0x7EFFA20. But I would expect 0xFA20 regardless of the platform. Where am I wrong?

Reply
  • I see that

    frame = (unsigned short)~marker<<11
    

    gives 0x7FEF800 on a 32 bitter, but why does not the cast remove the higher word? I see the compiler using the BIC instruction (with 0x1F0000) rather than shifts to perform the cast.
    You are right in the end I get 0x7EFFA20. But I would expect 0xFA20 regardless of the platform. Where am I wrong?

Children