I've often been bewildered I recall, by the "const" keyword in C. I know what it's supposed to do but it sometimes appears to be ignored.
look:
Then look:
Yet this other code compiles:
If the member "init_spi" has been declared as const why am I able to change it? but in this case its worse, because the declared struct instance is also const!
Furthermore, this compiles but why? it's meaningless surely?
look:
Code:
struct nrf_hal_support_interface
{
const void (*init_spi)(SPI_HandleTypeDef * spi_ptr);
void (*init_control_pins)();
void (*spi_ce_lo)(void *);
void (*spi_ce_hi)(void *);
void (*spi_cs_lo)(void *);
void (*spi_cs_hi)(void *);
void (*exchange_bytes)(void *, uint8_t[], uint8_t[], uint8_t);
void (*read_bytes)(void *, uint8_t bytes_in_ptr[], uint8_t count);
void (*write_bytes)(void *, uint8_t bytes_out_ptr[], uint8_t count);
void(*init_device)(SPI_HandleTypeDef * spi_ptr, NrfSpiDevice_ptr device_ptr, NrfIoDescriptor_ptr descriptor_ptr);
void(*flash_led_forever)(uint32_t interval);
};
Code:
const nrf_hal_support NrfHalSupport =
{
.init_spi = init_spi,
.init_control_pins = init_control_pins,
.spi_ce_lo = spi_ce_lo,
.spi_ce_hi = spi_ce_hi,
.spi_cs_lo = spi_cs_lo,
.spi_cs_hi = spi_cs_hi,
.exchange_bytes = exchange_bytes,
.read_bytes = read_bytes,
.write_bytes = write_bytes,
.init_device = init_device,
.flash_led_forever = flash_led_forever
};
Code:
NrfHalSupport.init_spi = NULL;
Furthermore, this compiles but why? it's meaningless surely?
Code:
static const void init_spi(SPI_HandleTypeDef * spi_ptr);

