Date: Mon, 1 Nov 2021 08:56:41 -0400
On Fri, Oct 29, 2021 at 10:00 PM Hubert Tong via Liaison
<liaison_at_[hidden]> wrote:
>
> It seems the C standard has a rule regarding the shift state of the spelling of string literals in the source file but neither the C standard nor the C++ standard specify what shift state should be observed just prior to the terminating NUL of a string literal. Is this lack of normative encouragement or requirement for the string to be in the initial shift state prior to the terminating NUL just a defect?
>
> Note that NUL is required by C to be encodable in any shift state; therefore, the need to insert NUL does not "naturally" cause strings in non-initial shift states to return to the initial shift state.
I'm by no means an expert in this area, but does 5.2.1.2p1-2 cover this?
1 ...
- A byte with all bits zero shall be interpreted as a null
character independent of shift state. Such a byte shall not occur as
part of any other multibyte character.
2 For source files, the following shall hold:
- An identifier, comment, string literal, character constant, or
header name shall begin and end in the initial shift state.
...
So NUL is required to be interpreted regardless of shift state (per
p1), and after the null, the string literal has to end in the initial
shift state (per p2).
(Sorry if I'm misunderstanding something. This may also be worth
asking on the SG16 mailing lists due to their expertise.)
~Aaron
>
> -- HT
> _______________________________________________
> Liaison mailing list
> Liaison_at_[hidden]
> Subscription: https://lists.isocpp.org/mailman/listinfo.cgi/liaison
> Link to this post: http://lists.isocpp.org/liaison/2021/10/0895.php
<liaison_at_[hidden]> wrote:
>
> It seems the C standard has a rule regarding the shift state of the spelling of string literals in the source file but neither the C standard nor the C++ standard specify what shift state should be observed just prior to the terminating NUL of a string literal. Is this lack of normative encouragement or requirement for the string to be in the initial shift state prior to the terminating NUL just a defect?
>
> Note that NUL is required by C to be encodable in any shift state; therefore, the need to insert NUL does not "naturally" cause strings in non-initial shift states to return to the initial shift state.
I'm by no means an expert in this area, but does 5.2.1.2p1-2 cover this?
1 ...
- A byte with all bits zero shall be interpreted as a null
character independent of shift state. Such a byte shall not occur as
part of any other multibyte character.
2 For source files, the following shall hold:
- An identifier, comment, string literal, character constant, or
header name shall begin and end in the initial shift state.
...
So NUL is required to be interpreted regardless of shift state (per
p1), and after the null, the string literal has to end in the initial
shift state (per p2).
(Sorry if I'm misunderstanding something. This may also be worth
asking on the SG16 mailing lists due to their expertise.)
~Aaron
>
> -- HT
> _______________________________________________
> Liaison mailing list
> Liaison_at_[hidden]
> Subscription: https://lists.isocpp.org/mailman/listinfo.cgi/liaison
> Link to this post: http://lists.isocpp.org/liaison/2021/10/0895.php
Received on 2021-11-01 07:56:56