Home Ask Login Register

Developers Planet

Your answer is one click away!

ultrasonic bananna February 2016

c syntax passing const pointer to const data to function

In the function declaration below the second argument is a const pointer to const data.

Below is example code calling the function. Why is there a (uint8_t *) before . Is this the usual syntax for passing a const pointer to a const data to a function? Are there other valid syntax?



Frodo February 2016

The define BANNER_STR is an array of characters as its type, in other words a string. And therefore in your function call you need to cast this argument to avoid compiler warnings but this is a valid way to call this function.

An other valid syntax would be instead of using define directive to declare a constant variable which contains the string to write:

const char banner_str[] = "Hello, world!\n\n";
ti_uart_write_buffer(TI_UART_0, (uint8_t *)banner_str, sizeof(banner_str));

Post Status

Asked in February 2016
Viewed 1,142 times
Voted 5
Answered 1 times


Leave an answer

Quote of the day: live life