当前位置:网站首页>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
边栏推荐
- Introduction to functions (inline functions and function overloading)
- Alicloud development board vscode development environment setup
- How to use Android studio to create an Alibaba cloud Internet of things app
- SystemC time
- Summary of virtual box usage problems
- Lua tvalue structure
- Chapter IV expression
- 肝了一个月的原创小袁个人博客项目开源啦(博客基本功能都有,还包含后台管理)
- 对于跨境电商,更侧重收入的出价策略 —Google SEM
- Mémoire de l'examen d'entrée à l'université
猜你喜欢

Communication flow analysis

Single bus temperature sensor 18B20 data on cloud (Alibaba cloud)

Player actual combat 21 audio and video synchronization

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

Greed issues - Egypt scores

Player practice 18 xresample

Compile and install lamp architecture of WordPress and discuz for multi virtual hosts based on fastcgi mode

程序分析与优化 - 6 循环优化

NotePad 常用设置

CSDN博客积分规则
随机推荐
Introduction to database system (Fifth Edition) notes Chapter 1 Introduction
Backtracking: Prime Rings
Bridging and net
NotePad 常用设置
2000. reverse word prefix
Binary tree traversal
Lua callinfo structure, stkid structure resolution
Alibaba cloud development board haas510 responds to UART serial port instructions
通信流量分析
使用make方法创建slice切片的坑
If you want to build brand awareness, what bidding strategy can you choose?
For cross-border e-commerce, the bidding strategy focusing more on revenue - Google SEM
The original Xiaoyuan personal blog project that has been around for a month is open source (the blog has basic functions, including background management)
Leetcode 2176. Count equal and divisible pairs in an array
Alicloud development board vscode development environment setup
Running phase of SystemC
Dismantle and modify the advertising machine - Amateur decompression
[early knowledge of activities] list of recent activities of livevideostack
Player practice 20 audio thread and video thread
对于跨境电商,更侧重收入的出价策略 —Google SEM