Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I am trying to figure out what this does.

   

located in the hids.c file;

   

line     220            keyboard_data[2u] = 0u;                       /* Set up keyboard data*/
line     221            keyboard_data[3u] = 0u;                       /* Set up keyboard data*/

   

 

   

What is the purpose of these two lines?

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Welcome in the forum!

   

The trailing 'u' after an integer constant advises the compiler to treat the number as an "unsigned" item. To use this qualifier after every constant (if needed or not) conforms to the "MISRA" coding rules which imho do not make readability easier. Companies as Cypress are bound to follow these rules. So the above lies could have been written as

   

line     220            keyboard_data[2] = 0;                       /* Set up keyboard data*/
line     221            keyboard_data[3] = 0;                       /* Set up keyboard data*/

   

which is more the usual C-language style.

   

 

   

Bob

View solution in original post

0 Likes
1 Reply
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Welcome in the forum!

   

The trailing 'u' after an integer constant advises the compiler to treat the number as an "unsigned" item. To use this qualifier after every constant (if needed or not) conforms to the "MISRA" coding rules which imho do not make readability easier. Companies as Cypress are bound to follow these rules. So the above lies could have been written as

   

line     220            keyboard_data[2] = 0;                       /* Set up keyboard data*/
line     221            keyboard_data[3] = 0;                       /* Set up keyboard data*/

   

which is more the usual C-language style.

   

 

   

Bob

0 Likes