Defect Report # 209
Submitter: Douglas A. Gwyn (J11)
Submission date: 19 Oct. 1999
Reference Document: WG14 N896 (J11 99-031)
Subject: Problem implementing INTN_C macros
Issue:
The requirements of subclause 7.18.4.1 may be impossible to satisfy
(for N
=8 or 16, typically)
unless an implementation has special (non-standard) support
for integer constants of types char
and short
:
The macro INTN_C(
value)
shall expand to a signed integer constant with the specified value
and type int_leastN_t
.
(Similarly for UINTN_C
.) 
The paragraph preceding this overly restrictive specification
reflects the actual intent:
a type with at least the specified width.
Possible Solutions:
-
Change "integer constant" to "integer constant expression". 
While this still does not reflect the original intent, at least it permits accurate implementation
without special support from the compiler.
-
Specify that the type shall be the promoted type
corresponding to
int_leastN_t
.
-
Specify that the type shall be any appropriately signed integer type of sufficient width.
Proposed Technical Correction:
In subclause 7.18.4.1 paragraph 2,
change the two occurrences of "and type"
to
"and [un]signed integer type at least as wide as".
Discussed Problems:
- An integer constant can only have one of 6 types unless compiler magic is used.
- Expressions for #if can't use casts.
- Expressions can't have a type narrower than int without casts.
Discussed Proposal:
If we allow the expansion to be an expression, it will be easier to
implement. We can avoid the need for casts by making the
expressions expand to the promoted type (as the _MAX macros do).
These macros can then be trivially implemented as:
#define INT42_C(value) ((INT42_MAX-INT42_MAX)+(value))
#define UINT42_C(value) ((UINT42_MAX-UINT42_MAX)+(value))
Proposed Technical Corrigendum:
7.18.4 Macros for integer constants
[#1] The following function-like macros220 expand to
integer constant expressions 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.
[#2] The argument in any instance of these macros shall be a
decimal, octal, or hexadecimal constant (as defined in
6.4.4.1) with a value that does not exceed the limits for
the corresponding type.
Add:
[#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 that is an object of the
corresponding type converted according to the integer
promotions. The value of the expression shall be that of the
argument.
Most of this wording is taken almost exactly from <limits.h>
7.18.4.1 Macros for minimum-width integer constants
Remove:
[#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)
221 For each name described in 7.18.1.2 that the
implementation provides, the corresponding macro in this subclause is required.
Change #2 to:
[#2] 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.
7.18.4.2 Macros for greatest-width integer constants
[#1] The following macro expands to an integer constant
expression having the value specified by its argument and the type intmax_t:
INTMAX_C(value)
The following macro expands to an integer constant expression having the value specified by its argument and the type uintmax_t:
UINTMAX_C(value)
Previous Defect Report < - >
Next Defect Report