Skip to content

Inidicate that code blocks contain C++#206

Merged
colin-home merged 1 commit intoMicrosoftDocs:masterfrom
robert-andrzejuk:patch-2
Apr 5, 2018
Merged

Inidicate that code blocks contain C++#206
colin-home merged 1 commit intoMicrosoftDocs:masterfrom
robert-andrzejuk:patch-2

Conversation

@robert-andrzejuk
Copy link
Copy Markdown
Contributor

No description provided.

@robert-andrzejuk
Copy link
Copy Markdown
Contributor Author

robert-andrzejuk commented Apr 3, 2018

This code requires more updates:

C++ has no built-in byte type. Use unsigned char to represent a byte value.

This is not true anymore from C++17.

Copy link
Copy Markdown
Contributor

@colin-home colin-home left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. Thanks for contributing!

Regarding the comment about the byte type, I could find no reference to a fundamental type named byte in either the C++17 or draft C++20 standard. There's a library type named std::byte in C++20, but it's not part of the underlying language.

@colin-home colin-home merged commit cff1a8a into MicrosoftDocs:master Apr 5, 2018
@robert-andrzejuk
Copy link
Copy Markdown
Contributor Author

Do I understand correctly that comment to be tongue in cheek?

std::byte is a part of C++17.

In light of Your answer then this part is not true :

Use unsigned char to represent a byte value.

But also please consider that this document http://open-std.org/JTC1/SC22/WG21/docs/papers/2017/p0298r3.pdf says:

Taken altogether, std::byte is just as “builtin” as if it was designated by dedicated keyword

@robert-andrzejuk robert-andrzejuk deleted the patch-2 branch April 8, 2018 19:17
@robert-andrzejuk
Copy link
Copy Markdown
Contributor Author

The last draft standard for C++17 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4640.pdf

A search for std::byte reveals many special cases for it to be handled like a builtin type.

@colin-home
Copy link
Copy Markdown
Contributor

There's now a std::byte is in C++20 as part of <cstddef>, in section 21.2.1, along with a handy set of operators. I'd certainly recommend its use in any new code that turns on the /std:c++latest switch. However, my search of the C++17 draft standard you linked reports no hits for std::byte at all. And even Neil's paper that you refer to is basically showing how a library implementation is good enough to act as if it were part of the language - but specifically states that it can't be part the language, or at least, not under that name. Far too much code exists that defines byte either with the preprocessor or as a typedef or alias UDT (usually as unsigned char), and it would all break. That Would Be Bad.

@colin-home
Copy link
Copy Markdown
Contributor

Ah, I must apologize, I now see that std::byte did make it into the final C++17 standard after all. I should have looked at that, instead of the earlier drafts. You are right, it does get mentioned in a few places, but my reading of the standard indicates that these references to std::byte don't require any special compiler behavior, and should work for any UDT defined the same way. It's still a library type, not built-in. And you can get it with /std:c++17 as well as /std:c++latest, which is handy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants