From 7ba68dd20dc34147cd545479edde909c6c4f8832 Mon Sep 17 00:00:00 2001 From: Jean-Francois Simon Date: Wed, 16 Nov 2022 16:19:50 +0100 Subject: [PATCH] Proper C/C++ struct initialization. --- mongoose.h | 1 + test/mip_test.c | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/mongoose.h b/mongoose.h index 9c051df1..6f7dee46 100644 --- a/mongoose.h +++ b/mongoose.h @@ -1467,6 +1467,7 @@ struct mip_if { }; void mip_init(struct mg_mgr *, struct mip_if *); +void mip_free(struct mip_if *); extern struct mip_driver mip_driver_stm32; extern struct mip_driver mip_driver_enc28j60; diff --git a/test/mip_test.c b/test/mip_test.c index 790646d8..fecbb25b 100644 --- a/test/mip_test.c +++ b/test/mip_test.c @@ -179,18 +179,22 @@ static void test_http_fetch(void) { mg_mgr_init(&mgr); // Initialise event manager // MIP driver - struct mip_driver driver; - { + + // Zero init fields required (C/C++ style diverge) + #ifndef __cplusplus + struct mip_driver driver = {.tx = tap_tx, .up = tap_up, .rx = tap_rx}; + struct mip_if mif = {.use_dhcp = true, .driver = &driver, .driver_data = &fd}; + #else + struct mip_driver driver {}; driver.tx = tap_tx; driver.up = tap_up; driver.rx = tap_rx; - } - struct mip_if mif; - { + struct mip_if mif {}; mif.use_dhcp = true; mif.driver = &driver; mif.driver_data = &fd; - } + #endif + sscanf(mac, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &mif.mac[0], &mif.mac[1], &mif.mac[2], &mif.mac[3], &mif.mac[4], &mif.mac[5]);