当前位置:网站首页>Nesting of C language annotations
Nesting of C language annotations
2022-06-12 14:18:00 【zou_ albert】
Mainstream C/C++/Java/C# Other languages , The annotation syntax is designed not to be nested .
Such as : /* xxx /* yyy */ zzz */ It's illegal. .
reason :
Notes are used to write descriptive language , Nesting makes readability worse .
But in fact , Annotations are not just used to write annotations , It is also commonly used to mask code blocks . When you need to comment out a large program , Still use this annotation ( /* … * /) How about ?
The answer, of course, is : Not good. !!!
If the program to be annotated has already been annotated with this annotator , Then another annotation like this may cause problems . Some compilers are detecting "/*" Will look for the nearest " */" Combined with it .
So how to annotate large programs ?
C In language
#if 0
#endif
Such a statement can accomplish this task .
This is a precompiled statement , The compiler automatically recognizes the precompiled code , Judge if Is it true , If set up , Just put ****1 Code retention ,****2 Comment out the code , This is done by the compiler . This will not affect the compilation and migration of the program , Such as :
#if 0
、
****1
/*..........*/
、
#else
、
****2
/*..........*/
、
#endif
Source of problem :
《C Traps and defects 》
practice 1-1.
some C The compiler allows nested comments . Please write a test program , requirement : Whether for compilers that allow nested annotations , Sea lions do not allow nested annotation compilers , The program can be compiled normally ( No error message appears ), But the results of program execution in these two cases are different .
Tips : In a string enclosed in double quotation marks , annotator /* Part of a string , The double quotation marks in the comments are part of the comments
Thoughts
- To form nested annotations , This string sequence must contain :/* /**/*/.
- First, let's discuss :/*/**/ . For compilers that do not allow nested annotations , This is a complete comment ; For compilers that allow nested annotations , The following characters are part of the comment .
- Let's add :"* /", Turn it into :/* /**/"*/".
- For compilers that do not allow nested annotations : The above string is equivalent to the string :"*/". Compilers that allow nested comments cannot be compiled at this time ( There is a double quotation mark left )
- So we followed it with a comment and a double quotation mark :/* /**/"* /"/*" .
- For compilers that allow nested annotations : The above string is equivalent to "/* " ; For compilers that do not allow nested annotations : The above string is equivalent to " * /" / *"( Comment terminator caused by parentheses , Followed by an open comment
- Finally, simply let the last comment end :/* /** /"* /"/*"/**/
- So if nested comments are allowed , The above string is equivalent to "/*" , If nested annotations are not allowed, they are equivalent to " */"
Reference link :https://blog.csdn.net/weixin_33859693/article/details/117036478
边栏推荐
- Why do Chinese programmers change jobs?
- 完美收官|详解 Go 分布式链路追踪实现原理
- Briefly describe the difference between CGI and fastcgi
- 正点原子STM32F429核心板的插座型号
- Ppt cannot be opened, always prompt how to fix it
- 阿里云开发板HaaS510将串口获取数据发送到物联网平台
- Knowledge of wireless card driver
- Design of PLC intelligent slave station based on PROFIBUS DP protocol
- SystemC common errors
- Remote code injection
猜你喜欢

TestEngine with ID ‘junit-vintage‘ failed to discover tests

阿里云开发板HaaS510将串口获取数据发送到物联网平台

Lua callinfo structure, stkid structure resolution

Alibaba cloud development board haas510 sends the serial port data to the Internet of things platform

Why do Chinese programmers change jobs?

SystemC common errors

Implementation of Ackermann function with simulated recursion

Player practice 11 audio resampling

How to realize the bidding strategy that pays more attention to transformation in the company's operation Google sem

Postgresql14 installation and use tutorial
随机推荐
Llvm 13.1 new pass plug-in form [for win]
Chapter IV expression
SystemC simulation scheduling mechanism
高考回憶錄
Implementation of Ackermann function with simulated recursion
Is Shell Scripting really a big technology?
Void pointer (void*) usage
公司运营中更注重转化的出价策略,如何实现? —Google sem
Solve the problem that IEEE latex template cannot display Chinese
SystemC common errors
正点原子STM32F429核心板的插座型号
Implementation and debug of process hiding under x64
Shell脚本到底是什么高大上的技术吗?
Postgresql14 installation and use tutorial
阿里云开发板HaaS510响应UART串口指令
Program analysis and Optimization - 6 loop optimization
My resume.
Notepad common settings
TestEngine with ID ‘junit-vintage‘ failed to discover tests
How to realize the bidding strategy that pays more attention to transformation in the company's operation Google sem