Of course it's something we needed so long ago.
My 2 cents: what about adding another member, "network" or alike, which will always be equal to big, so people (like me) don't need to go and look for it (e.g. when writing conversion code). My second comment is that maybe it's worth mentioning something about how this relates to the work being done in the networking TS (any relationship at all? Could be used to implement hton/ntoh functioms family, opens the possibility for new functioms or interfaces? Just a paragraph).
Very nice work Howard. Hope this gets into the std soon.
Daniel.
>
> Howard
>
> --
> You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
> To post to this group, send email to std-pr...@isocpp.org.
> To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/E80B5A8A-BAAE-4B69-8F91-8A1836C7456D%40gmail.com.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/np9av5%24tit%241%40blaine.gmane.org.
class endian
once it exists. At a minimum we need class endian
..."This subclause describes the endianness of the execution environment.
This subclause describes the byte ordering of all scalar types within the execution environment.
uint32_t val = 0x12345678;
unsigned char arr[sizeof(uint32_t)];
memcpy(arr, val, sizeof(uint32_t));
if constexpr (endian::native == endian::little)
assert(arr[0] == 0x78);
else if constexpr (endian::native == endian::big)
assert(arr[0] == 0x12);
The only comment I have is about your explanation, which talks about "most
significant byte placed first". In fact, this applies also to bits and, thus, to
bitfields. Which brings the criticism about macros back into focus. Here's an
example that I added to Qt in 5.8:
On Friday, August 19, 2016 at 7:34:52 PM UTC-7, Howard Hinnant wrote:http://howardhinnant.github.io/endian.html
is headed towards the pre-Issaquah mailing.
I’m providing a preview here for review purposes. Constructive criticism will be gratefully read, and if acted upon will be acknowledged.
What about a system for which sizeof(long long) == 1? In other words, a system in which all standard types are the same size, with an address space addressable in words instead of what we'd more typically call "bytes"? Not that I know of such a system.
In such a system, there is no such thing as endianness (as in byte order). I guess that it would be handled similarly to PDP endianness?
Finally, I've heard that some systems have unusual forms of endianness for floating-point numbers but not for integers, or possibly having opposite endianness. (Wikipedia lists older ARM systems' doubles--perhaps before hardware floating-point in ARM?) How would those systems be handled?
On Friday, August 19, 2016 at 8:01:01 PM UTC-7, Thiago Macieira wrote:
The only comment I have is about your explanation, which talks about "most
significant byte placed first". In fact, this applies also to bits and, thus, to
bitfields. Which brings the criticism about macros back into focus. Here's an
example that I added to Qt in 5.8:
As far as I know, there is also no requirement that endianness of the system control the order of bits in bitfields...? In practice, that is the case, though.
Melissa
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/2d31b898-9277-496d-97da-fcb19645b221%40isocpp.org.
On Aug 30, 2016, at 2:21 PM, Nicol Bolas <jmck...@gmail.com> wrote:
>
> On Tuesday, August 30, 2016 at 10:39:10 AM UTC-4, Howard Hinnant wrote:
>> On Aug 30, 2016, at 3:56 AM, Myriachan <myri...@gmail.com> wrote:
>>> >
>>> >
>>> >
>>> > Finally, I've heard that some systems have unusual forms of endianness for floating-point numbers but not for integers, or possibly having opposite endianness. (Wikipedia lists older ARM systems' doubles--perhaps before hardware floating-point in ARM?) How would those systems be handled?
>>>
>> One of the tried-and-true techniques of standardization is to:
>>
>> Standardize existing practice.
>>
>> __ORDER_LITTLE_ENDIAN__, __ORDER_BIG_ENDIAN__ and __BYTE_ORDER__ are existing practice with at least two major compilers (probably more but I don’t have them available to check). This proposal simply packages this existing practice using modern C++ tools.
>>
> What good is standardizing existing practice if you can't actually say what that existing practice means? That's the part that doesn't make sense here.
>
> The standard specifies behavior. Unless these values are tied into genuinely observable behavior, then standardizing them doesn't really accomplish anything. And if they are tied into genuinely observable behavior, then we need to know what that behavior is.
>
> I don't understand the point of standardizing three numbers without giving any meaning to these numbers.
I have no doubt that the LWG (or LEWG) will offer improvements to the wording. But note that we have been living with the concept of endian in the C++ standard for half a decade and the sky hasn’t fallen (yet). See [locale.stdcvt] for our current use of the terms little endian and big endian.
The proposal’s current description of endian is borrowed from what the POSIX standard says about it (http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html), which seems like a pretty good straw man to get the process started. To the best of my knowledge, no one has complained that the POSIX description of endian is meaningless.
unsigned char bytes[sizeof(T)];
std::memcpy(bytes, &n, sizeof(T));
T m = 0;
for (std::size_t i = 0; i < sizeof(T); ++i)
{
m = static_cast<T>((m << std::numeric_limits<unsigned char>::digits) + bytes[i]);
}