It may not be clear from the title. I came across the following code in an embedded STM32 project. I don't understand the line inside the function.
static void txend1(UARTDriver *uartp) {
(void)uartp; // what does this do? Is it a statement?
}
I've tried searching elsewhere online, but most results are casting pointers to void pointers, which I don't think this is. Thanks for the help!
The void pointer in C is a pointer that is not associated with any data types. It points to some data location in the storage. This means that it points to the address of variables. It is also called the general purpose pointer. In C, malloc() and calloc() functions return void * or generic pointers.
void *p( p is a void pointer) is a pointer which we can be explicitly cast to any data type. These pointers show difference only during dereferencing of pointers.
(void)argc; (void)argv; If a function argument is not used, like in your program, then this is the idiomatic way of suppressing the warning of unused function argument issued by some compilers. Any decent compiler will not generate code with these statements.
Description. The C library function void free(void *ptr) deallocates the memory previously allocated by a call to calloc, malloc, or realloc.
this is just a portable way to suppress the warning on this unused uart
parameter.
It has no effect, but compilers see that as used, and don't issue any warning.
Very useful when the prototype of the function is imposed / cannot be changed (callback function) but your implementation doesn't need this parameter.
(note that gcc
favors the __attribute__((unused))
construct, easier to understand, but not compatible with all compilers)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With