mercredi 7 août 2019

Can you specify a number literal is uint8?

Lets say I have this code:

uint8_t num;

num = 0xffU;

So, this all good. But I am using as strict warning levels as I can (without going mad) and setting warnings to errors to enforce our team to keep on top of compiler warnings.

What this means though is that we end up writing alot of this:

num = static_cast<uint8_t>(0xffU);

Which is a bit of a pain (not that much of a pain though). But it would be really nice if we can specify somthing like:

num = 0xffU8;

Is there a way to specify a number literal that is unsigned and 8-bits so we don't have to cast it? (same for uint16, 32 etc...)?

Aucun commentaire:

Enregistrer un commentaire