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

Why is string defined with half '0's?

Hi,

I see the following C lines on a ARM M4 Cortex CPU. It is new for me to see those interleaved '0's among character letters.

Could you explain it to me?

 

Thanks,

 

 

 

 

 

 

const uint8_t g_pui8ControlInterfaceString[] =

{ 2 + (21 * 2), USB_DTYPE_STRING,

’A’, 0, ’C’, 0, ’M’, 0, ’ ’, 0, ’C’, 0, ’o’, 0, ’n’,

0, ’t’, 0, ’r’, 0, ’o’, 0, ’l’, 0, ’ ’, 0, ’I’, 0, ’n’,

0, ’t’, 0, ’e’, 0, ’r’, 0, ’f’, 0, ’a’, 0, ’c’, 0, ’e’, 0

};

  • This is a generic C programming language question; the 0's in the above statement simply result in the production of 8-bit integers of value 0. The 'A' / 'C' etc. produce the 8-bit integer representing the relevant character (in the execution environment's encoding), and 0 could have been written as '\0'. It is my understanding that USB uses a form of UTF16 for encoding strings, and the 0's above are potentially there to pad the 8-bit character values to 16-bit ones.