|
| 1 | +// bindgen-flags: -- -std=c++14 |
| 2 | +// (C23 is not available in clang 9.0, but C++14 supports the same literals) |
| 3 | + |
| 4 | +// Binary integer literals (C23) - 0b10 is 2 in decimal |
| 5 | + |
| 6 | +#define DEFINE_BIN_LITERAL 0b10 |
| 7 | +#define DEFINE_NEG_BIN_LITERAL -0b10 |
| 8 | +const int CONST_INT_BIN_LITERAL = 0b10; |
| 9 | +const int CONST_INT_NEG_BIN_LITERAL = -0b10; |
| 10 | + |
| 11 | +// Octal integer literals - 010 is 8 in decimal |
| 12 | + |
| 13 | +#define DEFINE_OCT_LITERAL 010 |
| 14 | +#define DEFINE_NEG_OCT_LITERAL -010 |
| 15 | +const int CONST_INT_OCT_LITERAL = 010; |
| 16 | +const int CONST_INT_NEG_OCT_LITERAL = -010; |
| 17 | + |
| 18 | +// Hexadecimal integer literals - 0x10 is 16 in decimal |
| 19 | + |
| 20 | +#define DEFINE_HEX_LITERAL 0x10 |
| 21 | +#define DEFINE_NEG_HEX_LITERAL -0x10 |
| 22 | +const int CONST_INT_HEX_LITERAL = 0x10; |
| 23 | +const int CONST_INT_NEG_HEX_LITERAL = -0x10; |
| 24 | + |
| 25 | +// Default decimal integer literals - 10 is 10 in decimal |
| 26 | + |
| 27 | +#define DEFINE_DEC_LITERAL 10 |
| 28 | +#define DEFINE_NEG_DEC_LITERAL -10 |
| 29 | +const int CONST_INT_DEC_LITERAL = 10; |
| 30 | +const int CONST_INT_NEG_DEC_LITERAL = -10; |
| 31 | + |
| 32 | +// Enums with binary, octal, and hexadecimal integer literals |
| 33 | + |
| 34 | +enum MultiRadixLiteral { |
| 35 | + ENUM_BIN_LITERAL = 0b10, |
| 36 | + ENUM_NEG_BIN_LITERAL = -0b10, |
| 37 | + ENUM_OCT_LITERAL = 010, |
| 38 | + ENUM_NEG_OCT_LITERAL = -010, |
| 39 | + ENUM_HEX_LITERAL = 0x10, |
| 40 | + ENUM_NEG_HEX_LITERAL = -0x10, |
| 41 | + ENUM_DEC_LITERAL = 10, |
| 42 | + ENUM_NEG_DEC_LITERAL = -10, |
| 43 | +}; |
| 44 | + |
| 45 | +// Edge cases: minimum i64s |
| 46 | + |
| 47 | +const long long MIN_I64_BIN = -0b1000000000000000000000000000000000000000000000000000000000000000; |
| 48 | +const long long MIN_I64_OCT = -01000000000000000000000; |
| 49 | +const long long MIN_I64_DEC = -9223372036854775808; |
| 50 | +const long long MIN_I64_HEX = -0x8000000000000000; |
| 51 | + |
| 52 | +// Big B or big X |
| 53 | + |
| 54 | +const int BIG_B_BIN = 0B1; |
| 55 | +const int BIG_X_HEX = 0XF; |
| 56 | + |
| 57 | +// Octal with extra leading zero |
| 58 | + |
| 59 | +const char AGENT = 007; |
| 60 | + |
| 61 | +// C23 and C++14 thousands'/digit separator ' |
| 62 | + |
| 63 | +const unsigned long long SEP_BIN = 0b11111111'00000000; |
| 64 | +const unsigned long long SEP_OCT = 07777'7777'7777; |
| 65 | +const unsigned long long SEP_DEC = 299'792'458; |
| 66 | +const unsigned long long SEP_HEX = 0x1111'bbbb'cccc'dddd; |
| 67 | + |
| 68 | +// Multiple declarations |
| 69 | + |
| 70 | +const long BIN_1ST = 0b10101010, OCT_2ND = 0777, DEC_3RD = 1234, HEX_4TH = 0xffff; |
| 71 | + |
| 72 | +// Smaller integer types |
| 73 | + |
| 74 | +const unsigned short USHORT_HEX = 0xFFFF; |
| 75 | +const short SHORT_HEX = 0x7FFF; |
| 76 | +const unsigned char UCHAR_HEX = 0xFF; |
| 77 | +const char CHAR_HEX = 0x7F; |
0 commit comments