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
  • Because two arbitrary compilers generate different output, and thus the test fails. Being "portable" is a pretty broad requirement.

    Neither line generates what one might expect, although it's not clear what you expect as a result, or what you were really trying to code. Some better commentary, and a manually worked example might prove illustrative.

    A more liberal use of parenthesis might make things clearer to a casual observer. I find the inversions and shifts to be problematic.

    Line 1 and 2 respectively generate
    0000FA20, FFEFFA20
    07FEFA20, FFFFFA20

Reply
  • Because two arbitrary compilers generate different output, and thus the test fails. Being "portable" is a pretty broad requirement.

    Neither line generates what one might expect, although it's not clear what you expect as a result, or what you were really trying to code. Some better commentary, and a manually worked example might prove illustrative.

    A more liberal use of parenthesis might make things clearer to a casual observer. I find the inversions and shifts to be problematic.

    Line 1 and 2 respectively generate
    0000FA20, FFEFFA20
    07FEFA20, FFFFFA20

Children