1. Changelog
1.1. Revision 0 - June 5th, 2025
-
Initial release.
2. Introduction & Motivation
During the Wednesday, June 4th, 2025 SG22 meeting, a few invididuals voiced some potential concern that the ordering of parameters -- particularly
and
-- could confuse users. While it was pointed out that the formula that applied was the same no matter the ordering of parameters and that the entire
directive needed to be processed no matter what order was used, some still voiced a preference for providing a hard error about providing e.g. the
parameter in an
directive after the
parameter.
To answer their concerns, this paper proposes 2 versions of the same text. One is a hard-error based wording (ill-formed "shall" in C++, a shall-based wording under a Constraints section in C++). The other is a soft-error/warning based wording ("Recommended practice" section in both C++ and C). It is left up to the Committee to choose.
As it stands now, no implementation currently imposes an ordering. The parameters can be provided in any order and it does not change behavior. This is both the C23 behavior for existing parameters, and the extension parameters such as
and
.
Note: The paper authors for
and the
parameter ([p3540], [n3490]), as well as this paper, do not care and thinks this is not worth the investment. Nevertheless, the Committees can decide if they want it, and in what form.
3. Design
The design for this is not any kind of in-depth and is simple. According to both the discussion in SG22 and just generally understanding the consequences of justifying "the order of operations is important" (even if it, again, does not matter for existing implementations and nobody has implemented it like that), there’s 3 general principles here.
-
needs to appear beforeoffset
because it is applied in the algorithm before thelimit
is calculated.limit -
needs to appear beforelimit
,if_empty
, andprefix
.suffix -
if
is not present,limit
still needs to come beforeoffset
,if_empty
, andprefix
.suffix
The reason for the second and third constraints is because needs to be in this order because it changes whether or not the resource is considered empty of not (and thus affects whether or not any of the following parameters trigger).
4. Wording
This wording is relative to C++'s latest working draft.
4.1. Intent
The intent of this wording is to provide 2 options for the Committee to chose from:
-
ill-formed if the order of parameters is not in the way that the Committee demands it;
-
or, recommended practice to diagnose the ordering of parameters.
The choice is left to a vote by the Evolution Working Groups.
4.2. Proposed Language Wording
4.2.1. HARD ERROR VERSION: Add a new paragraph after (currently) paragraph 12 in [cpp.embed.gen]
…The method by which a sequence of preprocessing tokens between a
and a
< preprocessing token pair or a pair of
> characters is combined into a single resource name preprocessing token is implementation-defined.
" Certain preprocessor parameters have to appear before other preprocessor embed parameters in a specific order.
, if present, shall appear before
offset , if present.
limit both
and
offset , if present, shall appear before
limit ,
if_empty , and
prefix .
suffix [ Note: Similar diagnostics for implementation-defined embed parameters, which may be better understood in a specific order, also have the potential to clarify semantics. - end Note ]
4.2.2. RECOMMENDED PRACTICE: Add a new paragraph after (currently) paragraph 12 in [cpp.embed.gen]
…The method by which a sequence of preprocessing tokens between a
and a
< preprocessing token pair or a pair of
> characters is combined into a single resource name preprocessing token is implementation-defined.
" _Recommended Practice:_ Certain embed parameters should appear before other preprocessor embed parameters in a specific order.
, if present, should appear before
offset , if present.
limit both
and
offset , if present, should appear before any of
limit ,
if_empty , or
prefix .
suffix This aids in comprehension, as no matter where an
appears, it is always applied before the value in a
offset parameter. Similarly, as
limit and
limit can change if a resource is considered empty or not, each of these should appear in their proper order before
offset ,
if_empty , or
suffix . Implementations should consider applying similar diagnostics for implementation-defined embed parameters which might potentially be better understood in a specific order.
prefix
5. Acknowledgements
Thank you to SG22 for getting the discussion of this paper off the ground.