示例工程 ch10-ffi

ch10-ffi/native/c/add.h

c · 0.7 KB

/* ch10 · C 侧:三个函数覆盖数值、字符串往返、回调。
 *
 * 所有导出符号都走 C ABI(`extern "C"`),这是它能被 Dart 的 dart:ffi 调用的前提。
 */
#ifndef CH10_ADD_H
#define CH10_ADD_H
 
#include <stdint.h>
 
#ifdef __cplusplus
extern "C" {
#endif
 
/* 数值:基本传参与返回值 */
int32_t add_i32(int32_t a, int32_t b);
double mul_f64(double a, double b);
 
/* 字符串:由 C 侧 malloc 分配,调用方必须通过 free_string 释放 */
char *concat_strings(const char *a, const char *b);
void free_string(char *s);
 
/* 回调:C 侧调用 Dart 传进来的函数指针 */
int32_t apply_cb(int32_t (*cb)(int32_t), int32_t x);
 
#ifdef __cplusplus
}
#endif
 
#endif /* CH10_ADD_H */