Proper C/C++ struct initialization.

This commit is contained in:
Jean-Francois Simon 2022-11-16 16:19:50 +01:00
parent aeab3ef7ac
commit 7ba68dd20d
2 changed files with 11 additions and 6 deletions

View File

@ -1467,6 +1467,7 @@ struct mip_if {
}; };
void mip_init(struct mg_mgr *, 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_stm32;
extern struct mip_driver mip_driver_enc28j60; extern struct mip_driver mip_driver_enc28j60;

View File

@ -179,18 +179,22 @@ static void test_http_fetch(void) {
mg_mgr_init(&mgr); // Initialise event manager mg_mgr_init(&mgr); // Initialise event manager
// MIP driver // 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.tx = tap_tx;
driver.up = tap_up; driver.up = tap_up;
driver.rx = tap_rx; driver.rx = tap_rx;
} struct mip_if mif {};
struct mip_if mif;
{
mif.use_dhcp = true; mif.use_dhcp = true;
mif.driver = &driver; mif.driver = &driver;
mif.driver_data = &fd; mif.driver_data = &fd;
} #endif
sscanf(mac, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &mif.mac[0], &mif.mac[1], &mif.mac[2], 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]); &mif.mac[3], &mif.mac[4], &mif.mac[5]);