cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC™ Creator & Designer

Anonymous
Not applicable

Do you really need all those little u's (unsigned designators) everywhere?

   

I'm very fluent in visually reading "hexadecimal" data. As such, all those little  u's are really annoying.

   

If the array is already type casted with uint8, do we still need to add the u suffix to the data entries?

   

This slows me down significantly in my coding efficiency.

   

See below for an example.

   

--------------------------- too many u's --------------------------------------

   

/* I2C Read service UUID*/

   

const uint8 I2CReadUUID[16] = {

   

0x00u, 0x00u, 0xFBu, 0x34u, 0x9Bu, 0x5Fu, 0x80u, 0x00u, \

   

0x00u, 0x80u, 0x00u, 0x10u, 0x01u, 0x00u, 0x0Au, 0x00u \

   

};

   

---------------------- BETTER and more READABLE ----------------------

   

/* I2C Read service UUID*/

   

const uint8 I2CReadUUID[16] = {

   

0x00, 0x00, 0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, \

   

0x00, 0x80, 0x00, 0x10, 0x01, 0x00, 0x0A, 0x00 \

   

};

0 Likes
1 Solution
Bob_Marlowe
Expert II

There is a coding standard named "MISRA" that tells some stupid things are required. Not only the "u"s are part of that, what annoys me is that comments using double slashes are not allowed. Companies like Cypress are bound to confirm to MISRA rules.

   

 

   

Bob

View solution in original post

0 Likes
5 Replies
Bob_Marlowe
Expert II

There is a coding standard named "MISRA" that tells some stupid things are required. Not only the "u"s are part of that, what annoys me is that comments using double slashes are not allowed. Companies like Cypress are bound to confirm to MISRA rules.

   

 

   

Bob

View solution in original post

0 Likes
Anonymous
Not applicable

ahhh...

   

Well.. I'M NOT adhering To MISRA standards... you can count me out of that!

   

But the question remains.. can I eliminate the "u"s and freely use double slash comments without erroneous results if I so choose to do so?

0 Likes
Bob_Marlowe
Expert II

Keep calm, relax! As long as the compiler does not quail over bad unreadable code you may use anything or leave it out. You probably need the "u" in the following case:

   

int i;  //That's signed

   

    i = 0x80;  // is that a -128 or a 127 ?

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I'm good with the u's when necessary.

   

Thanks for the pointers.

0 Likes
Bob_Marlowe
Expert II

You're always welcome!

   

 

   

Bob

0 Likes