gpt4 book ai didi

c - 为什么 printf 不能编译?

转载 作者:太空狗 更新时间:2023-10-29 15:58:19 26 4
gpt4 key购买 nike

我正在阅读关于 C 的 Kernigan 和 Ritchie 手册。

出现下面的例子:

printf("hello, world
");

书上说 C 编译器会产生一条错误消息。编译器究竟是如何检测到这一点的,为什么这是一个问题?它不应该把换行符(大概在世界尽头)读作没有空格吗?

最佳答案

不允许在字符串文字中使用换行符,我们可以通过查看 C99 draft standard 中的语法来了解这一点6.4.5 字符串文字部分:

string-literal:
" s-char-sequenceopt "
L" s-char-sequenceopt "
s-char-sequence:
s-char
s-char-sequence s-char
s-char:
any member of the source character set except
the double-quote ", backslash \, or new-line character

我们可以看到 s-char 允许除 "\new-line 之外的任何字符。

关于c - 为什么 printf 不能编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21246312/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com