[技术问答] 为什么代码最后一行要加个回车

[复制链接]
1338|19
 楼主| koala889 发表于 2022-4-13 15:37 | 显示全部楼层 |阅读模式
MDK5
文件的最后,一定要有回车么?

没有就报错(警告),有就没事

翻了C语言的书,也没提这个

各位有没有同样的问题
huquanz711 发表于 2022-4-14 08:45 来自手机 | 显示全部楼层
没有说啊。
qiangtech 发表于 2022-4-14 09:19 | 显示全部楼层
是这样的,MDK会这样,有些编译器没有这个要求。
jasontu 发表于 2022-4-14 09:32 | 显示全部楼层
No need to add a space. Just move to the end of the last line in the file. Then press enter and save.

The warning is there because some tools will only process text that ends with a new-line character, so if the last text isn't followed by a new-line, that text will be ignored.

Almost all tools really process file data to the last character instead of to the last new-line character, but the compiler warning is there just to make sure that you don't get hurt if you move your code between different tools.
 楼主| koala889 发表于 2022-4-14 09:38 | 显示全部楼层
qiangtech 发表于 2022-4-14 09:19
是这样的,MDK会这样,有些编译器没有这个要求。

那可以在那里设置一下么?
或者说,每次想着多加几个回车
 楼主| koala889 发表于 2022-4-14 09:39 | 显示全部楼层
jasontu 发表于 2022-4-14 09:32
No need to add a space. Just move to the end of the last line in the file. Then press enter and save ...

嗯,看半天,大概意思明白了
qiangtech 发表于 2022-4-14 09:42 | 显示全部楼层
koala889 发表于 2022-4-14 09:38
那可以在那里设置一下么?
或者说,每次想着多加几个回车

我就是敲完最后多加两个回车,或者提示后加两个回车。
资深技术 发表于 2022-4-15 14:44 | 显示全部楼层
原因不知,我就是加两个回车
foxsbig 发表于 2022-4-18 13:13 | 显示全部楼层
keil的问题,习惯就好,倒不费事
tpgf 发表于 2022-5-3 18:42 | 显示全部楼层
这个不一定啊
drer 发表于 2022-5-3 18:52 | 显示全部楼层
是不是软件自己加上去的啊
qcliu 发表于 2022-5-3 18:59 | 显示全部楼层
不一定 这个是个人习惯
coshi 发表于 2022-5-3 19:11 | 显示全部楼层
并不是必要的
kxsi 发表于 2022-5-3 19:27 | 显示全部楼层
不是 一定 是个人需求或者是习惯
wiba 发表于 2022-5-3 19:33 | 显示全部楼层
这个无所谓吧 加不加都行 加几个也都行
kiwis66 发表于 2022-5-6 11:44 | 显示全部楼层
mdk专有属性
alxd 发表于 2022-5-24 09:36 | 显示全部楼层
编译器的问题,跟C语言没啥关系
Charlotte夏 发表于 2022-5-24 09:44 | 显示全部楼层
我觉得C语言好像没这么复杂吧
Candic12e 发表于 2022-5-24 10:08 | 显示全部楼层
这个好像是编译器对格式的要求,最后一行要回车
Belle1257 发表于 2022-5-24 11:35 | 显示全部楼层
我也遇到过这种警告,报错不至于
您需要登录后才可以回帖 登录 | 注册

本版积分规则

85

主题

473

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部