【发布时间】:2016-03-11 21:15:30
【问题描述】:
在下面的代码中,函数print_uart传输字符串“Hello world”时,*s中究竟收到了什么?是字符H还是存储字符串“Hello World”的内存地址??
volatile unsigned int * const UART0DR = (unsigned int *)0x101f1000;
void print_uart0(const char *s)
{
while(*s != '\0')
{ /* Loop until end of string */
*UART0DR = (unsigned int)(*s); /* Transmit char */
s++; /* Next char */
}
}
void c_entry()
{
print_uart0("Hello world!\n");
}
【问题讨论】:
-
volatile unsigned int * const- 这意味着恒定和易变 -
s是指针,*s是字符值。*UAT0DR = (...)(*s)使用价值。 -
@Ed,指针是
const,它指向的东西是volatile。 -
@chux - 没想到这一点。谢谢