| ... | @@ -1553,6 +1553,61 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1553,6 +1553,61 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1553 | "pub const NOT_ZERO = ~c_uint(0);", | 1553 | "pub const NOT_ZERO = ~c_uint(0);", |
| 1554 | ); | 1554 | ); |
| 1555 | | 1555 | |
| | 1556 | cases.addC("implicit casts", |
| | 1557 | \\#include <stdbool.h> |
| | 1558 | \\ |
| | 1559 | \\void fn_int(int x); |
| | 1560 | \\void fn_f32(float x); |
| | 1561 | \\void fn_f64(double x); |
| | 1562 | \\void fn_char(char x); |
| | 1563 | \\void fn_bool(bool x); |
| | 1564 | \\void fn_ptr(void *x); |
| | 1565 | \\ |
| | 1566 | \\void call(int q) { |
| | 1567 | \\ fn_int(3.0f); |
| | 1568 | \\ fn_int(3.0); |
| | 1569 | \\ fn_int(3.0L); |
| | 1570 | \\ fn_int('ABCD'); |
| | 1571 | \\ fn_f32(3); |
| | 1572 | \\ fn_f64(3); |
| | 1573 | \\ fn_char('3'); |
| | 1574 | \\ fn_char('\x1'); |
| | 1575 | \\ fn_char(0); |
| | 1576 | \\ fn_f32(3.0f); |
| | 1577 | \\ fn_f64(3.0); |
| | 1578 | \\ fn_bool(123); |
| | 1579 | \\ fn_bool(0); |
| | 1580 | \\ fn_bool(&fn_int); |
| | 1581 | \\ fn_int(&fn_int); |
| | 1582 | \\ fn_ptr(42); |
| | 1583 | \\} |
| | 1584 | , |
| | 1585 | \\pub extern fn fn_int(x: c_int) void; |
| | 1586 | \\pub extern fn fn_f32(x: f32) void; |
| | 1587 | \\pub extern fn fn_f64(x: f64) void; |
| | 1588 | \\pub extern fn fn_char(x: u8) void; |
| | 1589 | \\pub extern fn fn_bool(x: bool) void; |
| | 1590 | \\pub extern fn fn_ptr(x: ?*c_void) void; |
| | 1591 | \\pub export fn call(q: c_int) void { |
| | 1592 | \\ fn_int(@floatToInt(c_int, 3.000000)); |
| | 1593 | \\ fn_int(@floatToInt(c_int, 3.000000)); |
| | 1594 | \\ fn_int(@floatToInt(c_int, 3.000000)); |
| | 1595 | \\ fn_int(1094861636); |
| | 1596 | \\ fn_f32(@intToFloat(f32, 3)); |
| | 1597 | \\ fn_f64(@intToFloat(f64, 3)); |
| | 1598 | \\ fn_char(u8('3')); |
| | 1599 | \\ fn_char(u8('\x01')); |
| | 1600 | \\ fn_char(u8(0)); |
| | 1601 | \\ fn_f32(3.000000); |
| | 1602 | \\ fn_f64(3.000000); |
| | 1603 | \\ fn_bool(true); |
| | 1604 | \\ fn_bool(false); |
| | 1605 | \\ fn_bool(@ptrToInt(&fn_int) != 0); |
| | 1606 | \\ fn_int(@intCast(c_int, @ptrToInt(&fn_int))); |
| | 1607 | \\ fn_ptr(@intToPtr(?*c_void, 42)); |
| | 1608 | \\} |
| | 1609 | ); |
| | 1610 | |
| 1556 | // cases.add("empty array with initializer", | 1611 | // cases.add("empty array with initializer", |
| 1557 | // "int a[4] = {};" | 1612 | // "int a[4] = {};" |
| 1558 | // , | 1613 | // , |