Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions c2rust-transpile/src/translator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4282,6 +4282,13 @@ impl<'c> Translation<'c> {
target_ty,
)))
})
} else if target_ty_ctype.is_pointer() && source_ty_kind.is_bool() {
val.and_then(|x| {
Ok(WithStmts::new_val(mk().cast_expr(
mk().cast_expr(x, mk().path_ty(vec!["libc", "size_t"])),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really should change these to core::ffi:: instead of libc:: at some point, but it's fine here; that's what we've done so far.

target_ty,
)))
})
} else {
// Other numeric casts translate to Rust `as` casts,
// unless the cast is to a function pointer then use `transmute`.
Expand Down
1 change: 1 addition & 0 deletions tests/casts/src/casts.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ void cast_stuff(void) {

bool b = true;
float x15 = b;
void* x16 = (void*)b;
}