In the function declaration below the second argument is a const pointer to const data.
ti_rc_t ti_uart_write_buffer(const ti_uart_t uart, const uint8_t *const data, uint32_t len);
Below is example code calling the function. Why is there a (uint8_t *) before BANNER_STR. Is this the usual syntax for passing a const pointer to a const data to a function? Are there other valid syntax?
#define BANNER_STR ("Hello, world!\n\n")
ti_uart_write_buffer(TI_UART_0, (uint8_t *)BANNER_STR, sizeof(BANNER_STR));
Thanks
consts there are a promise by the function that it won't modify the pointer (not that that makes much sense) or the data pointed to - it is not a restriction on the caller (ie. the caller can pass in aconstor non-constpointer toconstor non-constdata).(uint8_t *)before BANNER_STR refer to?BANNER_STRfromconst char*touint8_t*before passing it to the function.constvariable array or pointer with the text.charanduint8_tare usually incompatible types; a cast is necessary to do pointer-based aliasing like this. You are focusing onconstbut that is a red herring. They could have written(const uint8_t *)with the same end result. Theuint8_t *value result of the cast will be implicitly converted toconst uint8_t *to match the function parameter anyway