| author | |
| committer | |
| log | da506aaf6ea731c72daaac649dba788407db0d6c |
| tree | bf453b98b793cf85e13132056a691289c17dd612 |
| parent | 50457482b16dc402ad0eff9f7990258257e2dd62 |
| signature |
2 files changed, 18 insertions(+), 0 deletions(-)
src/translate_c.zig+8| ... | ... | @@ -2380,6 +2380,14 @@ fn transCCast( |
| 2380 | 2380 | }); |
| 2381 | 2381 | } |
| 2382 | 2382 | if (cIsFloating(src_type) and !cIsFloating(dst_type)) { |
| 2383 | // bool expression: floating val != 0 | |
| 2384 | if (qualTypeIsBoolean(dst_type)) { | |
| 2385 | return Tag.not_equal.create(c.arena, .{ | |
| 2386 | .lhs = expr, | |
| 2387 | .rhs = Tag.zero_literal.init(), | |
| 2388 | }); | |
| 2389 | } | |
| 2390 | ||
| 2383 | 2391 | // @as(dest_type, @intFromFloat(val)) |
| 2384 | 2392 | return Tag.as.create(c.arena, .{ |
| 2385 | 2393 | .lhs = dst_node, |
test/cases/run_translated_c/explicit_cast_bool_from_float.c created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | #include <stdbool.h> | |
| 2 | ||
| 3 | int main() { | |
| 4 | float f = 2.0f; | |
| 5 | bool b = (bool) f; | |
| 6 | return 0; | |
| 7 | } | |
| 8 | ||
| 9 | // run-translated-c | |
| 10 | // c_frontends=aro,clang |