Sujet : Re: C23 thoughts and opinions
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 28. May 2024, 21:54:31
Autres entêtes
Organisation : None to speak of
Message-ID : <87sey1y7w8.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10 11
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Keith Thompson <Keith.S.Thompson+
u@gmail.com> writes:
[...]
The *embed element width* is typically going to be CHAR_BIT bits by
default. It can only be changed by an *implementation-defined* embed
parameter. It seems odd that there's no standard way to specify the
element width.
>
It seems even more odd that the embed element width is
implementation defined and not set to CHAR_BIT by default.
A conforming implementation could set the embed element width to,
say, 4*CHAR_BIT and then not provide an implementation-defined embed
parameter to specify a different width, making #embed unusable for
unsigned char arrays. (N3220 is a draft, not the final C23 standard,
but I haven't heard about any changes in this area.)
[...]
I was wrong about this. The default embed element width is CHAR_BIT.
It can be changed by an implementation-defined embed parameter;
implementations aren't required to support such a parameter.
The term "embed element width" is defined in N3220 6.10.4.1p6, under
Constraints:
Let *embed element width* be either:
- an integer constant expression greater than zero determined by
an implementation-defined embed parameter; or,
— CHAR_BIT (5.2.5.3.2).
The result of (*resource width*) % (*embed element width*) shall be
zero.
with a footnote:
This constraint helps ensure data is neither filled with padding
values nor truncated in a given environment, and helps ensure the
data is portable with respect to usages of memcpy (7.26.2.1) with
character type arrays initialized from the data.
And of course CHAR_BIT is the byte size on the target (relevant for
cross-compilers). In the odd case where CHAR_BIT is different on the
host and target systems, the embedded file needs to be one that could be
used on the target (if the target supports files).
It's probably reasonable for an implementation to support *only*
CHAR_BIT as the embed element width, and not to provide a mechanism to
change it.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */