This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Fastest minimum-width integer types and limits macros
Gunther Nikl <gnikl@users.sourceforge.net> writes:
> 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
>
> in that case?
>
> So this is not about user code but an implementation question.
The value of INT_FAST8_MIN is implementation defined, so you can choose
whatever value you like (as long as it is <= -128). That said, the
standard seems to suggest that the value should correspond to the value
of the underlying type. That is, if int_fast8_t is defined as int, then
the value of INT_FAST8_MIN should be INT_MIN. That at least makes
INT_FAST8_MIN useful, as otherwise it would always simply have the value
-128.
Ian