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

Byte order CPP definition not defined on FreeBSD #8089

Closed
ysangkok opened this issue Apr 16, 2020 · 4 comments
Closed

Byte order CPP definition not defined on FreeBSD #8089

ysangkok opened this issue Apr 16, 2020 · 4 comments

Comments

@ysangkok
Copy link

Version of OpenTTD

1.10.1

Expected result

Compiles without warnings

Actual result

/home/janus/openttd-1.10.1/src/script/api/../../core/endian_type.hpp:45:22: warning: "__LITTLE_ENDIAN" is not defined, evaluates to 0 [-Wundef]
   45 | # if __BYTE_ORDER == __LITTLE_ENDIAN

Steps to reproduce

$ clang --version
FreeBSD clang version 9.0.1 (git@github.com:llvm/llvm-project.git c1a0a213378a458fbea1a5c77b315c7dce08fd05) (based on LLVM 9.0.1)
Target: x86_64-unknown-freebsd12.1
Thread model: posix
InstalledDir: /usr/bin
@glx22
Copy link
Contributor

glx22 commented Apr 16, 2020

I guess

#elif defined(__OpenBSD__)
needs some improvements

@LordAro
Copy link
Member

LordAro commented Apr 16, 2020

On my FreeBSD system:

$ clang++ -dM -E -x c++ - < /dev/null | grep ENDIAN
#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
#define __LITTLE_ENDIAN__ 1
#define __ORDER_BIG_ENDIAN__ 4321
#define __ORDER_LITTLE_ENDIAN__ 1234
#define __ORDER_PDP_ENDIAN__ 3412

(also __FreeBSD__ define for detection)

@dwfreed
Copy link

dwfreed commented Apr 16, 2020

For the record:

$ g++ --version
g++ (Debian 8.3.0-6) 8.3.0
$ g++ -dM -E -x c++ - < /dev/null | grep ENDIAN
#define __ORDER_LITTLE_ENDIAN__ 1234
#define __FLOAT_WORD_ORDER__ __ORDER_LITTLE_ENDIAN__
#define __ORDER_PDP_ENDIAN__ 3412
#define __ORDER_BIG_ENDIAN__ 4321
#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__

Looks like you could use #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ and have it be portable. This also works on OS X Mojave, though checking older versions might be a good idea too.

@glx22
Copy link
Contributor

glx22 commented Jun 5, 2020

With the merge of #7270 it should be fixed.

@glx22 glx22 closed this as completed Jun 5, 2020
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

No branches or pull requests

4 participants