示例工程 25-c-interop
25-c-interop/Sources/Ch25C/Ch25C.c
#include "Ch25C.h"
int32_t c_add(int32_t lhs, int32_t rhs) {
return lhs + rhs;
}
size_t c_strlen(const char *text) {
size_t length = 0;
while (text[length] != '\0') {
length++;
}
return length;
}
void c_fill(int32_t *buffer, size_t count, int32_t value) {
for (size_t index = 0; index < count; index++) {
buffer[index] = value;
}
}
Point2C c_make_point(int32_t x, int32_t y) {
Point2C point = {x, y};
return point;
}
int32_t c_sum_point(Point2C point) {
return point.x + point.y;
}
int32_t c_call_callback(int32_t (*callback)(int32_t), int32_t value) {
return callback(value);
}