Skip to content
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

No undefined behavior per C++ standard in detecting endianness. #195

Merged
merged 1 commit into from Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 6 additions & 8 deletions doctest/doctest.h
Expand Up @@ -2790,14 +2790,12 @@ namespace {
};

static Arch which() {
union _
{
int asInt;
char asChar[sizeof(int)];
} u;

u.asInt = 1; // NOLINT
return (u.asChar[sizeof(int) - 1] == 1) ? Big : Little; // NOLINT
int x = 1;
// casting any data pointer to char* is allowed
auto ptr = reinterpret_cast<char*>(&x);
if(*ptr)
return Little;
return Big;
}
};
} // namespace
Expand Down
14 changes: 6 additions & 8 deletions doctest/parts/doctest.cpp
Expand Up @@ -177,14 +177,12 @@ namespace {
};

static Arch which() {
union _
{
int asInt;
char asChar[sizeof(int)];
} u;

u.asInt = 1; // NOLINT
return (u.asChar[sizeof(int) - 1] == 1) ? Big : Little; // NOLINT
int x = 1;
// casting any data pointer to char* is allowed
auto ptr = reinterpret_cast<char*>(&x);
if(*ptr)
return Little;
return Big;
}
};
} // namespace
Expand Down