-
Notifications
You must be signed in to change notification settings - Fork 360
Open
Description
#[repr(C)]
pub struct Payload {
data: [u8; 128],
}
#[repr(C)]
pub struct Example {
callback: /* extern "C" */ fn(a: Payload, b: Payload),
}
#[unsafe(no_mangle)]
pub extern "C" fn test(input: Example) {}cbindgen-ing this code (for C) produces
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
typedef struct Payload {
uint8_t data[128];
} Payload;
typedef struct Example {
void (*callback)(struct Payload a, struct Payload b);
} Example;
void test(struct Example input);with no warnings or errors. However, the ABI for callback isn't necessarily the same in C and Rust without the extern "C". (I recently ran into this, and was confused why my structs-passed-by-value had garbage in them until I tracked down my mistake.)
Metadata
Metadata
Assignees
Labels
No labels