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

Bitwise portable issue #6

Open
apple-ouyang opened this issue Mar 17, 2022 · 4 comments
Open

Bitwise portable issue #6

apple-ouyang opened this issue Mar 17, 2022 · 4 comments

Comments

@apple-ouyang
Copy link
Owner

I found a stackoverflow post saying that the bitfield is not portable. The only portable code is using bit-wise operators.
So should we change to bit-wise operators?
@i404788

@i404788
Copy link
Contributor

i404788 commented Mar 17, 2022

It seems to be implementation-defined by the C standard although I believe it's consistent across the major compilers that support packed bitfields, I can do some tests for that. For little-endian machines a difference does need to be made (http://mjfrazer.org/mjfrazer/bitfields/), however that is also needed when using bit-wise operators (if the deltas are transferred across platforms).

@i404788
Copy link
Contributor

i404788 commented Mar 17, 2022

OSX:

  • GNU GCC-11 & Apple Clang 12 use the same layout.
    Linux:
  • LLVM clang 12 & GNU GCC-10 use the same layout
  • GNU GCC-6 & GNU GCC-10 use the same layout
  • MinGW32 has same layout when using -mno-ms-bitfields (seems like microsoft might implement it differently)

To test:

@apple-ouyang
Copy link
Owner Author

I look forward to seeing your test results

@i404788
Copy link
Contributor

i404788 commented Mar 17, 2022

I've completed testing, with some minor changes it does work across all compilers listed above (check the msvc gobolt link for the final code). I'll create a pull request later

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

2 participants