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

Use compiler macros for endianness #2688

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,12 @@ bool Image::isPrintICC(uint16_t type, Exiv2::PrintStructureOption option) {
}

bool Image::isBigEndianPlatform() {
#if defined(__BYTE_ORDER)
#if __BYTE_ORDER == __BIG_ENDIAN
#ifdef __LITTLE_ENDIAN__
return false;
#elif defined(__BIG_ENDIAN__)
return true;
#elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__)
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
return true;
#else
return false;
Expand All @@ -184,7 +188,11 @@ bool Image::isBigEndianPlatform() {
#endif
}
bool Image::isLittleEndianPlatform() {
#ifdef __LITTLE_ENDIAN__
return true;
#else
Comment on lines +191 to +193
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this macro (__LITTLE_ENDIAN__) sometimes defined when __BYTE_ORDER__ isn't? If so, maybe this logic should be moved to isBigEndianPlatform. I.e. add this to the beginning of isBigEndianPlatform:

#if defined(__BIG_ENDIAN__)
  return true;
#elif defined(__LITTLE_ENDIAN__)
  return false;
#elif ...

Copy link
Collaborator Author

@kmilos kmilos Jul 11, 2023

Choose a reason for hiding this comment

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

__LITTLE_ENDIAN__ is our own macro (potentially) defined in config.h.

Everything else comes from the compiler. AFAICT, there is no definition of __BIG_ENDIAN__.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is this macro (__LITTLE_ENDIAN__) sometimes defined when __BYTE_ORDER__ isn't?

Potentially on WIN32 and MSVC (which AFAIK does not define __BYTE_ORDER__):

#if defined(_WIN32) || defined(__CYGWIN__)

Copy link
Collaborator Author

@kmilos kmilos Jul 11, 2023

Choose a reason for hiding this comment

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

@kevinbackhouse I'm now leveraging these as well.

return !isBigEndianPlatform();
#endif
}

uint64_t Image::byteSwap(uint64_t value, bool bSwap) {
Expand Down