Fastest minimum-width integer types and limits macros
David Brown
david@westcontrol.com
Fri Sep 30 15:16:00 GMT 2011
On 30/09/2011 08:05, Gunther Nikl wrote:
> Ian Lance Taylor schrieb:
>> Gunther Nikl<gnikl@users.sourceforge.net> writes:
>>
>>> Is there a special requirement about the value of the limits
>>> macros for fastest minimum-width integers? Eg. would it be legal
>>> to use the limits of a a "signed char" if int_fast8_t is defined
>>> in terms of an int? Or is it required to use the proper limit of
>>> int?
>>
>> I don't understand what you mean. Can you show us some example code
>> that you are uncertain about?
>
> Here is an example for int_fast8_t:
>
> typedef signed char int_fast8_t;
> #define INT_FAST8_MIN INT8_MIN
> #define INT_FAST8_MAX INT8_MAX
>
> Now if int_fast8_t uses "int" as underlying type like this:
>
> typedef int int_fast8_t;
>
> which value is its MIN/MAX macros supposed to have? Is it
> allowed to use the same "char" limits as above or do I need
> to use
>
> #define INT_FAST8_MIN INT32_MIN
> #define INT_FAST8_MAX INT32_MAX
>
You mean "#define INT_FAST8_MIN INT_MIN" in this case - you would only
use "INT32_MIN" if you had "typedef int32_t int_fast8_t". If you are
going to write your own <stdint.h>, try to be accurate - otherwise
you'll end up with something that looks standard and portable, but is
not quite correct and will cause problems if it is reused on other
platforms.
I believe it is standard practice that INT_FAST8_MIN and similar limits
match those of the underlying type, even though it would be legal to
make it smaller. Similarly with INT_LEAST8_MIN. That seems to be the
case on the various compilers I have lying around.
> in that case?
>
> So this is not about user code but an implementation question.
>
> Thank you,
> Gunther Nikl
>
>
More information about the Gcc-help
mailing list