一、注释符号
C语言中的符号:
奖项:Best of show
功能:处理三种文件格式(PGM、PPM和ASCII Art)的采样工具
作者:Google华裔工程师Don Hsi-Yun Yang
注释符号,下面哪些注释是正确的。
#include <stdio.h>int main(){ int/*...*/i; // 注释由空格来代替,所以是正确的 char* s = "abcdefgh //hijklmn"; // 在双引号中的注释会当成字符,所以也不会报错,但与程序愿意不符 //Is it a \ valid comment? // ‘\’接续符,整个语句就是一个注释 in/*...*/t i; //会报错 return 0;}
gcc编译后出错结果:
[root@localhost 1]# gcc 1-1.c 1-1.c: In function ‘main’:1-1.c:11: error: ‘in’ undeclared (first use in this function)1-1.c:11: error: (Each undeclared identifier is reported only once1-1.c:11: error: for each function it appears in.)1-1.c:11: error: expected ‘;’ before ‘t’
注释规则小结:
1、编译器会在编译过程删除注释,但不是简单的删除而是用空格代替
2、编译器认为双引号括起来内容都是字符串,双斜杠也不例外
3、"/*........*/"型注释不能被嵌套
4、你觉得y = x/*p是什么意思?
作者本意:把x除以*p的结果赋值给y
编译器:将/*作为一段注释的开始,把/*后的内容都当成注释内容,直到*/出现为止
在编译器看来,注释和其它程序元素都是平等的,所以,作为程序员也不能看轻注释。
5、出色注释怎么来写
注释应该准确易懂,防止二义性,错误的注释有害而无利
注释是对代码的提示,避免臃肿和喧宾夺主
一目了然的代码避免加注释
不要用缩写来注释代码,这样可能会产生误解
注释用于阐述原因而不是用于描述程序的运行过程
下面是一个漂亮程序的截取部分:
/* ======================================================================== FILE: Form.c SERVICES: GENERAL DESCRIPTION: Concrete implementation of RootForm and base IForm methods ======================================================================== ======================================================================== Copyright ?1999-2005 QUALCOMM Incorporated All Rights Reserved. QUALCOMM Proprietary/GTDR ======================================================================== ======================================================================== */ /*================================================================================== XXXXXXX Confidential Proprietary (c) Copyright XXXXXXX - All Rights Reserved Revision History: Modification Author Date CR Number Major Changes ---------------------- ------------ ------------ ---------------------------- Daniel Rossler 01/18/2007 LIBkk94550 Add check for NULL pointers in order to avoid a panic ==================================================================================*/
// If there are still forms on the stack, then we need to set up several things: // 1. The topmost form is the active form // 2. All other forms are not active // 3. The topmost form is being listened to via mlFormActive // 4. The topmost non-popup form is being listened to via mlFormTopmostNonPopup // 5. The topmost non-popup form and all popup forms on top of it are shown // 6. Forms below the topmost non-popup form are now shown