1.1. Revision 1 - June 17th, 2022
Add constraint to prevent
literals from becoming extended integer types (will be a proper Constraint Violation).
1.2. Revision 0 - April 12th, 2022
Initial Release 🎉
Targeting C2y/C3a (after C23).
This is a (minor) compatibility issue with literal suffixes that may be potentially used in shared code in the future. C++ adopted suffixed literals for size_t in [p0330]. The design is as follows:
#include<stddef.h> size_t ulit_val = 0 zu ;
, as with current literals, can be placed on either the left or the right of the
suffix to make it unsigned. For symmetry with existing suffix literal rules, it also has a signed variant. That type is the "signed integer type of size_t", which normally resolves to
#include<stddef.h> ptrdiff_t lit_val = 0 z ;
The signed variant lacks the
as a piece of the
suffix. This also matches the way
adjusts specific codes to display
-sized variables. The design is simple and, thankfully, compatible with C++. It also provides a way to avoid signed comparison warnings in compilers which implement more strict comparisons checks, e.g., when comparing a
value against some fixed constant value.
2.1. Even After Compatibility, Do We Really Need This?
Yes. The trip to put this paper into C++ was an extremely long one and came with a ton of reasons. All of it can be seen in [p0330] and 90% of that reasoning applies to C, especially in the face of
Wording is relative to [N2912].
The goal of this wording is to provide:
a literal suffix for both the signed (
) or unsigned (
) variant of the type of the expression "
sizeof ( 0 )
use the suffix
in either the form
to produce a
3.2.1. Add two new grammar productions to §184.108.40.206 Integer constants¸ Syntax, ¶1
220.127.116.11 Integer constantsSyntax
- unsigned-suffix long-suffixopt
- unsigned-suffix long-long-suffix
- long-suffix unsigned-suffixopt
- long-long-suffix unsigned-suffixopt
- long-long-suffix: one of
- ll LL
3.2.2. Add two new table rows to §18.104.22.168 Integer constants¸ Semantics, ¶6; Modify ¶7
The type of an integer constant is the first of the corresponding list in which its value can be represented.
Suffix Decimal Constant Octal, Binary, or Hexadecimal Constant … … …
If an integer constant cannot be represented by any type in its list, it may have an extended integer type, if the extended integer type can represent its value. If all of the types in the list for the constant are signed, the extended integer type shall be signed. If all of the types in the list for the constant are unsigned, the extended integer type shall be unsigned. If the list contains both signed and unsigned types, the extended integer type may be signed or unsigned. If an integer constant cannot be represented by any type in its list and has no extended integer type, then the integer constant has no type.Forward references: preprocessing numbers (6.4.8), numeric conversion functions (7.22.1) .