In AVR-libc page 143 the implementation of the function uart_putchar()
is typical as the following:
#include <stdio.h>
static int uart_putchar(char c, FILE *stream);
static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
static int
uart_putchar(char c, FILE *stream)
{
if (c == '\n')
uart_putchar('\r', stream);
loop_until_bit_is_set(UCSRA, UDRE);
UDR = c;
return 0;
}
int
main(void)
{
init_uart();
stdout = &mystdout;
printf("Hello, world!\n");
return 0;
}
I know that we can redirect a specific stream to a stdout
or stdin
using fdevopen()
.
But is not the variable stream
is not used in this function?
Why is there such a variable that not used by the function? Is that because the fdevopen()
pointers to functions parameters?