Why a 8 bit variable got compiled as a 16 bit variable?

Viewed 404

I am taking over an old project using TI C2000. Compiled all fine, set break points, stepping through no problem.

Until I found a weird problem today: I defined an unsigned char variable, but can get a simple calculation right. I set a break point, and found out compiler made it into a 16 bit variable.

But 8 bit array is compiled as 8 bit no problem.

Screen shot attached here: enter image description here

If I treat it as a 16 bit in the software, everything is fine. But I never run into this type of issue before.

Source code is here:

    //check CRC
    unsigned char buf[4];
    unsigned char crc;
    buf[0] = commandWord >> 8;
    buf[1] = commandWord & 0xff;
    buf[2] = data[0] >> 8;
    buf[3] = data[0] & 0xff;
    crc = crc8(buf, 4);

    if (0xf000U == (safetyWord & 0xf000U)) {
        if ((crc & 0x00ff) == (safetyWord & 0x00ff)) {
            ret = TLE_SUCCESS;
        } else {
            ret = -1;
        }
    } else {
        ret = -1;
    }

I had to use crc & 0x00ff to make the software work.

1 Answers

On this platform 1 byte is 16 bits, so unsigned char is a 16-bit type. buf is an array of four 16-bit values.

Related