main.c :10:2 warning: no newline at the end of file

本文解释了为什么Linux下的程序文件必须以换行符结束的原因。主要涉及到两个方面:一是确保每一行都以换行符结束;二是避免行尾的连接符导致逻辑错误。文章还提供了一个具体的示例来说明这一点,并指出了一些编译器会自动在文件末尾插入换行符。

解决这个问题,只要linux下程序结尾必须以换行符结束就可以了。

 

这么规定的初衷有两个:
为了每一行都要以换行结束。
因为行尾的/表示连接下一行,如果一个文件最后一行(main函数的右边大括号)行尾有/,那么,紧跟它也被包含进来的下一个源文件的第一行就会被连接而如果一个文件以一个空行结束就会避免这种情况的发生。
例子:

       #include <stdio.h>   
  1. int main()  
  2. {  
  3.     printf("%d", /  
  4.     sizeof(int));  
  5.     return 0;  
  6. }  

上例中的第四个物理行和第五个物理行被反斜杠(/)连接成一个逻辑行(等价于printf("%d", sizeof(int)));

如果在第七行main函数的右大括号后面加上反斜杠的话,那么它就会和下一个文件的第一行连接,所以这里}之后要输入一个换行符,故要求每一行都要用换行结束。

注:有些编译器会自动在文件结束位置插入换行符。(譬如vi编辑器)

 

Rebuild started: Project: 工程模板 *** Using Compiler 'V5.06 update 7 (build 960)', folder: 'E:\keil5\MDK5.36\ARM\ARMCC\Bin' Rebuild target 'Target 1' assembling startup_stm32f10x_hd.s... compiling main.c... .\APP\dsgshow.h(16): warning: #1-D: last line of file ends without a newline #endif .\APP\delay.h(14): warning: #1-D: last line of file ends without a newline #endif /* __DELAY_H */ .\APP\EXTI.C(39): warning: #1-D: last line of file ends without a newline } .\APP\key.h(25): warning: #1-D: last line of file ends without a newline #endif User\main.c(27): warning: #1-D: last line of file ends without a newline } User\main.c: 5 warnings, 0 errors compiling stm32f10x_it.c... compiling misc.c... compiling beepkey.c... APP\delay.h(14): warning: #1-D: last line of file ends without a newline #endif /* __DELAY_H */ APP\beepkey.c(116): warning: #1-D: last line of file ends without a newline } APP\beepkey.c(77): warning: #177-D: variable "i" was declared but never referenced uint32_t i; // ??: ????????? APP\beepkey.c: 3 warnings, 0 errors compiling led.c... APP\led.c(32): warning: #1-D: last line of file ends without a newline } APP\led.c: 1 warning, 0 errors compiling stm32f10x_gpio.c... compiling system_stm32f10x.c... compiling stm32f10x_exti.c... compiling stm32f10x_rcc.c... compiling core_cm3.c... compiling systick.c... compiling delay.c... APP\delay.h(14): warning: #1-D: last line of file ends without a newline #endif /* __DELAY_H */ APP\delay.c(33): warning: #1-D: last line of file ends without a newline } APP\delay.c: 2 warnings, 0 errors compiling EXTI.C... APP\dsgshow.h(16): warning: #1-D: last line of file ends without a newline #endif APP\delay.h(14): warning: #1-D: last line of file ends without a newline #endif /* __DELAY_H */ APP\EXTI.C(39): warning: #1-D: last line of file ends without a newline } APP\EXTI.C: 3 warnings, 0 errors compiling key.c... APP\key.h(25): warning: #1-D: last line of file ends without a newline #endif APP\key.c(47): warning: #1-D: last line of file ends without a newline } APP\key.c: 2 warnings, 0 errors compiling dsgshow.c... APP\dsgshow.h(16): warning: #1-D: last line of file ends without a newline #endif APP\delay.h(14): warning: #1-D: last line of file ends without a newline #endif /* __DELAY_H */ APP\dsgshow.c: 2 warnings, 0 errors linking... .\Output\工程模板.axf: Error: L6200E: Symbol hour multiply defined (by dsgshow.o and main.o). .\Output\工程模板.axf: Error: L6200E: Symbol minute multiply defined (by dsgshow.o and main.o). .\Output\工程模板.axf: Error: L6200E: Symbol second multiply defined (by dsgshow.o and main.o). .\Output\工程模板.axf: Error: L6200E: Symbol smgduan multiply defined (by dsgshow.o and main.o). .\Output\工程模板.axf: Error: L6200E: Symbol smgwei multiply defined (by dsgshow.o and main.o). .\Output\工程模板.axf: Error: L6200E: Symbol DsgShowInit multiply defined (by dsgshow.o and main.o). .\Output\工程模板.axf: Error: L6200E: Symbol DsgShowNum multiply defined (by dsgshow.o and main.o). .\Output\工程模板.axf: Error: L6200E: Symbol DsgShowTime multiply defined (by dsgshow.o and main.o). .\Output\工程模板.axf: Error: L6200E: Symbol EXTI0_IRQHandler multiply defined (by stm32f10x_it.o and main.o). .\Output\工程模板.axf: Error: L6200E: Symbol EXTI0_IRQHandler multiply defined (by exti.o and main.o). .\Output\工程模板.axf: Error: L6200E: Symbol EXTI1_IRQHandler multiply defined (by stm32f10x_it.o and main.o). .\Output\工程模板.axf: Error: L6200E: Symbol EXTI1_IRQHandler multiply defined (by exti.o and main.o). .\Output\工程模板.axf: Error: L6200E: Symbol EXTI2_IRQHandler multiply defined (by stm32f10x_it.o and main.o). .\Output\工程模板.axf: Error: L6200E: Symbol EXTI2_IRQHandler multiply defined (by exti.o and main.o). .\Output\工程模板.axf: Error: L6200E: Symbol EXTI15_10_IRQHandler multiply defined (by exti.o and main.o). .\Output\工程模板.axf: Error: L6200E: Symbol delay_ms multiply defined (by delay.o and systick.o). .\Output\工程模板.axf: Error: L6200E: Symbol delay_us multiply defined (by delay.o and systick.o). Not enough information to list image symbols. Not enough information to list load addresses in the image map. Finished: 2 information, 0 warning and 17 error messages. ".\Output\工程模板.axf" - 17 Error(s), 18 Warning(s). Target not created. Build Time Elapsed: 00:00:01
06-17
*** Using Compiler 'V5.06 update 5 (build 528)', folder: 'E:\Keil5\ARM\ARMCC\Bin' Build target 'Template' compiling main.c... ./deep.h(10): warning: #1-D: last line of file ends without a newline #endif ./adc_key.h(9): warning: #1-D: last line of file ends without a newline void Key_Handler(void); ./vs1053.h(10): warning: #1-D: last line of file ends without a newline uint8_t VS1053_GetVolume(void); main.c(21): warning: #223-D: function "VS1053_Play_Process" declared implicitly VS1053_Play_Process(); main.c(26): warning: #1-D: last line of file ends without a newline } main.c: 5 warnings, 0 errors linking... ..\MOBAN.axf: Error: L6218E: Undefined symbol LCD_Init (referred from main.o). ..\MOBAN.axf: Error: L6218E: Undefined symbol VS1053_Init (referred from main.o). ..\MOBAN.axf: Error: L6218E: Undefined symbol VS1053_Play_Process (referred from main.o). ..\MOBAN.axf: Error: L6218E: Undefined symbol HAL_GetTick (referred from adc_key.o). ..\MOBAN.axf: Error: L6218E: Undefined symbol Play_Next (referred from adc_key.o). ..\MOBAN.axf: Error: L6218E: Undefined symbol Play_Prev (referred from adc_key.o). ..\MOBAN.axf: Error: L6218E: Undefined symbol VS1053_VolumeDown (referred from adc_key.o). ..\MOBAN.axf: Error: L6218E: Undefined symbol LCD_DrawNumber (referred from lcd_menu.o). ..\MOBAN.axf: Error: L6218E: Undefined symbol LCD_DrawString (referred from lcd_menu.o). Not enough information to list image symbols. Not enough information to list load addresses in the image map. Finished: 2 information, 0 warning and 9 error messages. "..\MOBAN.axf" - 9 Error(s), 5 Warning(s). Target not created. Build Time Elapsed: 00:00:02
07-06
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值