Skip to content

Commit fdb8870

Browse files
ehaasVexu
andcommitted
translate-c: promote large integer macros to unsigned long long if necessary
Closes #10793 Co-authored-by: Veikka Tuominen <[email protected]>
1 parent b45387f commit fdb8870

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

lib/std/zig/c_translation.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ test "sizeof" {
268268
pub const CIntLiteralRadix = enum { decimal, octal, hexadecimal };
269269

270270
fn PromoteIntLiteralReturnType(comptime SuffixType: type, comptime number: comptime_int, comptime radix: CIntLiteralRadix) type {
271-
const signed_decimal = [_]type{ c_int, c_long, c_longlong };
271+
const signed_decimal = [_]type{ c_int, c_long, c_longlong, c_ulonglong };
272272
const signed_oct_hex = [_]type{ c_int, c_uint, c_long, c_ulong, c_longlong, c_ulonglong };
273273
const unsigned = [_]type{ c_uint, c_ulong, c_ulonglong };
274274

test/behavior/translate_c_macros.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,5 @@ typedef _Bool uintptr_t;
4848

4949
#define CAST_TO_BOOL(X) (_Bool)(X)
5050
#define CAST_TO_UINTPTR(X) (uintptr_t)(X)
51+
52+
#define LARGE_INT 18446744073709550592

test/behavior/translate_c_macros.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,7 @@ test "cast functions" {
113113
try expectEqual(true, h.CAST_TO_BOOL(S.foo));
114114
try expect(h.CAST_TO_UINTPTR(S.foo) != 0);
115115
}
116+
117+
test "large integer macro" {
118+
try expectEqual(@as(c_ulonglong, 18446744073709550592), h.LARGE_INT);
119+
}

0 commit comments

Comments
 (0)