Last active
January 27, 2021 06:12
-
-
Save dlOuOlb/e949cf6fd70b96d21a494e807474637f to your computer and use it in GitHub Desktop.
Testing a myth that an integer, casted from a pointer, can be used to determine its alignment.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if __STDC__ | |
#else | |
# error A standard C compiler is required! | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "conf.h" | |
#include <stddef.h> /* size_t; offsetof. */ | |
extern int uMyth_( void ) | |
{ | |
typedef const struct { const char Trap; const size_t Gold; } BOX; | |
auto const size_t Rule[ 2 ] = { offsetof( BOX, Gold ), sizeof(size_t) }; | |
register const size_t | |
ConA = ( Rule[ 0 ] - 1 ) & ( Rule[ 0 ] | Rule[ 1 ] | (size_t) ( Rule + 0 ) ), | |
ConS = ( Rule[ 1 ] - 0 ) ^ ( (size_t) ( Rule + 1 ) - (size_t) ( Rule + 0 ) ); | |
return !( ConA | ConS ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "conf.h" | |
#include <stdlib.h> /* EXIT_FAILURE, EXIT_SUCCESS. */ | |
extern int main( void ) | |
{ | |
extern int uMyth_( void ); | |
return uMyth_( )? EXIT_SUCCESS: EXIT_FAILURE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compiler Tests
Special thanks to Compiler Explorer.
GCC
-Wall -Wextra -pedantic-errors -O2 -std=c89
x86-64 gcc 10.2
ARM64 gcc 8.2
RISC-V rv64gc gcc 8.2.0
PowerPC64 gcc 6.3.0
MIPS64 gcc 5.4
MSP430 gcc 6.2.1
Clang
-Wall -Wextra -pedantic-errors -O2 -std=c89
x86-64 clang 11.0.1
armv8-a clang 11.0.1
RISC-V rv64gc clang 11.0.1
MSVC
-WX -Wall -wd4820 -O2 -TC -Za
x64 msvc v19.14 (WINE)
ARM64 msvc v19.14 (WINE)
ICC
-Wall -Wextra -pedantic-errors -O2 -std=c89
x86-64 icc 19.0.1