-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes a technicality regarding the size of C's char
type
#89114
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Specifically, ISO/IEC 9899:2018 — better known as "C18" — (and at least C11, C99 and C89) do not specify the size of `byte` in bits. Section 3.6 defines "byte" as "addressable unit of data storage" while section 6.2.5 ("Types") only defines "char" as "large enough to store any member of the basic execution set" giving it a lower bound of 7 bit (since there are 96 characters in the basic execution set). With section 6.5.3.4 paragraph 4 "When sizeof is applied to an operant that has type char […] the result is 1" you could read this as the size of `char` in bits being defined as exactly the same as the number of bits in a byte but it's also valid to read that as an exception. In general implementations take `char` as the smallest unit of addressable memory, which for modern byte-addressed architectures is overwhelmingly 8 bits to the point of this convention being completely cemented into just about all of our software. So is any of this actually relevant at all? I hope not. I sincerely hope that this never, ever comes up. But if for some reason a poor rustacean is having to interface with C code running on a Cray X1 that in 2003 is still doing word-addressed memory with 64-bit words and they trust the docs here blindly it will blow up in her face. And I'll be truly sorry for her to have to deal with … all of that.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @yaahc (or someone else) soon. Please see the contribution instructions for more information. |
rust-highfive
added
the
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
label
Sep 20, 2021
@bors r+ Thank you for the clarification ^_^ |
📌 Commit 23c608f has been approved by |
bors
added
S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
and removed
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
labels
Sep 20, 2021
the8472
added
the
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
label
Sep 21, 2021
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Sep 21, 2021
Rollup of 12 pull requests Successful merges: - rust-lang#88795 (Print a note if a character literal contains a variation selector) - rust-lang#89015 (core::ascii::escape_default: reduce struct size) - rust-lang#89078 (Cleanup: Remove needless reference in ParentHirIterator) - rust-lang#89086 (Stabilize `Iterator::map_while`) - rust-lang#89096 ([bootstrap] Improve the error message when `ninja` is not found to link to installation instructions) - rust-lang#89113 (dont `.ensure()` the `thir_abstract_const` query call in `mir_build`) - rust-lang#89114 (Fixes a technicality regarding the size of C's `char` type) - rust-lang#89115 (:arrow_up: rust-analyzer) - rust-lang#89126 (Fix ICE when `indirect_structural_match` is allowed) - rust-lang#89141 (Impl `Error` for `FromSecsError` without foreign type) - rust-lang#89142 (Fix match for placeholder region) - rust-lang#89147 (add case for checking const refs in check_const_value_eq) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
flip1995
pushed a commit
to flip1995/rust
that referenced
this pull request
Sep 28, 2021
Rollup of 12 pull requests Successful merges: - rust-lang#88795 (Print a note if a character literal contains a variation selector) - rust-lang#89015 (core::ascii::escape_default: reduce struct size) - rust-lang#89078 (Cleanup: Remove needless reference in ParentHirIterator) - rust-lang#89086 (Stabilize `Iterator::map_while`) - rust-lang#89096 ([bootstrap] Improve the error message when `ninja` is not found to link to installation instructions) - rust-lang#89113 (dont `.ensure()` the `thir_abstract_const` query call in `mir_build`) - rust-lang#89114 (Fixes a technicality regarding the size of C's `char` type) - rust-lang#89115 (:arrow_up: rust-analyzer) - rust-lang#89126 (Fix ICE when `indirect_structural_match` is allowed) - rust-lang#89141 (Impl `Error` for `FromSecsError` without foreign type) - rust-lang#89142 (Fix match for placeholder region) - rust-lang#89147 (add case for checking const refs in check_const_value_eq) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Specifically, ISO/IEC 9899:2018 — better known as "C18" — (and at least
C11, C99 and C89) do not specify the size of
byte
in bits.Section 3.6 defines "byte" as "addressable unit of data storage" while
section 6.2.5 ("Types") only defines "char" as "large enough to store
any member of the basic execution set" giving it a lower bound of 7 bit
(since there are 96 characters in the basic execution set).
With section 6.5.3.4 paragraph 4 "When sizeof is applied to an operant
that has type char […] the result is 1" you could read this as the size
of
char
in bits being defined as exactly the same as the number ofbits in a byte but it's also valid to read that as an exception.
In general implementations take
char
as the smallest unit ofaddressable memory, which for modern byte-addressed architectures is
overwhelmingly 8 bits to the point of this convention being completely
cemented into just about all of our software.
So is any of this actually relevant at all? I hope not. I sincerely hope
that this never, ever comes up.
But if for some reason a poor rustacean is having to interface with C
code running on a Cray X1 that in 2003 is still doing word-addressed
memory with 64-bit chars and they trust the docs here blindly it will
blow up in her face. And I'll be truly sorry for her to have to deal
with … all of that.