Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: INTx_C/UINTx_C definitions result type



On Sun, Dec 05, 2010 at 22:11:32 +0100, Nicolas Joly wrote:

> I just noted that INTx_C/UINTx_C macros does not seems to return
> costants of the specified `uint_leastx_t' type as expected ...
>
>   7.18.4.1 Macros for minimum-width integer constants
[...]
> Actually only the smallest version (x < 32) suffers from this and
> sizeof(INT8_C(0)) = 4 differs from sizeof(int_least8_t) = 1.
> 
> Any drawbacks to be expected with the following patch that adds casts
> for the corresponding types ?

I think your patch is not correct.  What is the problem you are trying
to solve?


My old copy of ISO C FDIS says

       7.18.4  Macros for integer constants

       [#1]  The  following  function-like  macros220)  expand   to
       integer  constants  suitable  for  initializing objects that
       have  integer  types  corresponding  to  types  defined   in
       <stdint.h>.   Each  macro name corresponds to a similar type
       name in 7.18.1.2 or 7.18.1.5.

...

       7.18.4.1  Macros for minimum-width integer constants

       [#1]  Each  of  the  following  macros expands to an integer
       constant having the value specified by its  argument  and  a
       type with at least the specified width.221)


       [#2]  The  macro  INTN_C(value)  shall  expand  to  a signed
       integer  constant  with  the  specified   value   and   type
       int_leastN_t.   The  macro UINTN_C(value) shall expand to an
       unsigned integer constant with the specified value and  type
       uint_leastN_t.  [...]


Note that the requirement are: "suitable for initializing" in 7.18.4#1
and "at least the specified width" in 7.18.4.1#1.

7.18.4.1#2 says "and type int_leastN_t", which is confusing, but I
think it's the sloppy wording in #2.

Current draft http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1539.pdf
seems to clarify that properly:

  7.20.4 Macros for integer constants

  1 The following function-like macros expand to integer constants
    suitable for initializing objects that have integer types
    corresponding to types defined in <stdint.h>. Each macro name
    corresponds to a similar type name in 7.20.1.2 or 7.20.1.5.
  ...

  3 Each invocation of one of these macros shall expand to an integer
    constant expression suitable for use in #if preprocessing
    directives.  The type of the expression shall have the same type as
    would an expression of the corresponding type converted according to
    the integer promotions. The value of the expression shall be that of
    the argument.


  7.20.4.1 Macros for minimum-width integer constants

  1 The macro INTN_C(value) shall expand to an integer constant
    expression corresponding to the type int_leastN_t.  The macro
    UINTN_C(value) shall expand to an integer constant expression
    corresponding to the type uint_leastN_t. For example, if
    uint_least64_t is a name for the type unsigned long long int, then
    UINT64_C(0x123) might expand to the integer constant 0x123ULL.

Note in particular that 7.20.4#3 now explicitly talks about integer
promotions and mandates that the macro could be used in #if.

-uwe


Home | Main Index | Thread Index | Old Index