4 ms·
> I wonder if there is a way in C to reproduce this mechanism in order to not generate any check instructions as well for unsigned types. Correct me if I'm wro
by junon 5y ago
> I wonder if there is a way in C to reproduce this mechanism in order to not generate any check instructions as well for unsigned types.
Correct me if I'm wrong (I probably am, don't trust me) but simply using `unsigned` as the type gives you the most optimal signed unsigned integer type for the system.
- dumael 5y ago'signed' and 'unsigned' on their own--act as short-hand for 'signed int' and 'unsigned int' in C and C++. Note that the size of an 'int' is dependant on the "data model"[1]. As for whether it's the most optimal is far too context dependant. A data model that defaults 'int's to 32 bits on today's (and yesterday's) architectures is fine in many cases as the range of that type is acceptable for most usages without excessive wastage. Certain data models do specify that 'int' is 64 bits which can break some programmer's assumptions, and also lead to space wastage as a struct member or a stack slot has to have 64 bits allocated for it on paper. Data models are part of the ABI your program uses, so it's not necessarily optimal for any given system. [1] Wikipedia has a table summarizing some of the differences: https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_m...