mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-13 15:33:40 +00:00
cgo: implement rudimentary C array decaying
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.
This commit is contained in:
committed by
Ron Evans
parent
04e8f44370
commit
5c0a337c4f
Vendored
+4
@@ -144,3 +144,7 @@ extern int cflagsConstant;
|
||||
// test duplicate definitions
|
||||
int add(int a, int b);
|
||||
extern int global;
|
||||
|
||||
// Test array decaying into a pointer.
|
||||
typedef int arraydecay_buf3[4][7][2];
|
||||
void arraydecay(int buf1[5], int buf2[3][8], arraydecay_buf3 buf3);
|
||||
|
||||
Reference in New Issue
Block a user