This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Forcing unsigned char to store 1-byte

Hi,

I am working on C2000-F28027. I see that unsigned char stores 2-bytes(1 word) of data.

But in my case, I strictly want unsigned char to store 1-byte. Is there a way to force the unsigned char to store 1-byte?

I have refered the link http://processors.wiki.ti.com/index.php/Byte_Accesses_with_the_C28x_CPU. But the intrinsics __byte() and __mov_byte() are not helping me here.

Thanks & Regards,

Raghavendra

  • Raghavendra,

    The C compiler stores a char as a 16-bit value on C28x, as you noticed.  You cannot force a char to be 1 byte.

    What some people do is manually pack the chars by stuffing two char values into a 16 bit unsigned int.  You can then unpack them when you need to use them.  This is fairly effective when storing large string tables for, say, UART serial port transmission.  You're basically trading off MIPS vs. memory.  I've done this in the past using a structure with bit fields:

    struct BYTES {
     unsigned int LSB:8;
     unsigned int MSB:8;
    };

    const struct BYTES table[] = {'A','B','C','D'};

     

    Regards,

    David