
This is just a first step. It's not complete, but it gets some real world C code to parse. This signature, from the ESP-IDF: esp_err_t esp_wifi_get_mac(wifi_interface_t ifx, uint8_t mac[6]); Was previously converted to something like this (pseudocode): C.esp_err_t esp_wifi_get_mac(ifx C.wifi_interface_t, mac [6]uint8) But this is not correct. C array parameters will decay. The array is passed by reference instead of by value. Instead, this would be the correct signature: C.esp_err_t esp_wifi_get_mac(ifx C.wifi_interface_t, mac *uint8) So that it can be called like this (using CGo): var mac [6]byte errCode := C.esp_wifi_get_mac(C.ESP_IF_WIFI_AP, &mac[0]) This stores the result in the 6-element array mac.
67 строки
1,4 КиБ
C
67 строки
1,4 КиБ
C
#include "main.h"
|
|
|
|
int global = 3;
|
|
bool globalBool = 1;
|
|
bool globalBool2 = 10; // test narrowing
|
|
float globalFloat = 3.1;
|
|
double globalDouble = 3.2;
|
|
_Complex float globalComplexFloat = 4.1+3.3i;
|
|
_Complex double globalComplexDouble = 4.2+3.4i;
|
|
_Complex double globalComplexLongDouble = 4.3+3.5i;
|
|
char globalChar = 100;
|
|
void *globalVoidPtrSet = &global;
|
|
void *globalVoidPtrNull;
|
|
int64_t globalInt64 = -(2LL << 40);
|
|
collection_t globalStruct = {256, -123456, 3.14, 88};
|
|
int globalStructSize = sizeof(globalStruct);
|
|
short globalArray[3] = {5, 6, 7};
|
|
joined_t globalUnion;
|
|
int globalUnionSize = sizeof(globalUnion);
|
|
option_t globalOption = optionG;
|
|
bitfield_t globalBitfield = {244, 15, 1, 2, 47, 5};
|
|
|
|
int cflagsConstant = SOME_CONSTANT;
|
|
|
|
int smallEnumWidth = sizeof(option2_t);
|
|
|
|
int fortytwo() {
|
|
return 42;
|
|
}
|
|
|
|
int add(int a, int b) {
|
|
return a + b;
|
|
}
|
|
|
|
int doCallback(int a, int b, binop_t callback) {
|
|
return callback(a, b);
|
|
}
|
|
|
|
int variadic0() {
|
|
return 1;
|
|
}
|
|
|
|
int variadic2(int x, int y, ...) {
|
|
return x * y;
|
|
}
|
|
|
|
void store(int value, int *ptr) {
|
|
*ptr = value;
|
|
}
|
|
|
|
void unionSetShort(short s) {
|
|
globalUnion.s = s;
|
|
}
|
|
|
|
void unionSetFloat(float f) {
|
|
globalUnion.f = f;
|
|
}
|
|
|
|
void unionSetData(short f0, short f1, short f2) {
|
|
globalUnion.data[0] = 5;
|
|
globalUnion.data[1] = 8;
|
|
globalUnion.data[2] = 1;
|
|
}
|
|
|
|
void arraydecay(int buf1[5], int buf2[3][8], int buf3[4][7][2]) {
|
|
// Do nothing.
|
|
}
|