在所有的编程语言中,只有C语言和非C语言,C是
贴地飞行的艺术
!C is described as
high-level and portable assembly language
, and one of the first applications cross-compiled for any new CPU architecture will be a C compiler!
++i
,i++
和i+=N
的汇编一样,是否比i=i+1
或i=i+N
快,看编译器了,gcc编译后用objdump -d
看,都一样(x86_64)!从语义上看,单独使用时++i
更优(如果i是C++的迭代器,++i的速度更快),比如for循环,写成这样也不用加括号:++*ip
(对*ip
做+1
,*ip++
是先取值后对ip
指针+1
)。
EOF
= -1(d), 4294967295(u), 0xFFFFFFFF,EOF是int
,不是char!(char在arithmetic operation中会自动执行Integral Promotion)
float
和double
浮点型数据,也可以执行++
和--
,但不推荐,也较危险!(浮点数)用哪个macro来判断host的byte order呢?(判断字节序)
使用assignment operator
op=
,也许可以帮助编译器生成更高效的代码,而且code is more compact!op可以是:+,-,*,/,%,<<,>>,&,^,|
。expr1 op= expr2
等价于expr1 = (expr1) op (expr2)
。Type conversion is always tricky and buggy! For ternary operator
?:
, if f is a float and n is an int, thenn>0?f:n
is of type float regardless of whether n is positive.signed int无限右移后是
-1
,无限左移后是0
!移位补0,但signed number的右移是例外。(右移变小,左移变大,signed整数,最小-1,最大0)
malloc后
和new后
检查,free后
和delete后
赋NULL或nullptr(防止double free),accordingly!(free(NULL)和delete nullptr很OK,无需额外检查)C语言选择了这种用
\0
字符作为字符串的结束符(NULL terminated string);strlen
的结果不包含最后的\0
!(发现strlen的问题)There are 6 [white]space characters in ASCII set.
不建议使用
multi-char literal
语法,有warning,而且有implementation-defined details.条件编译由预处理器完成,预处理器不能计算sizeof,它由编译器计算。
-- 目录[2] --
-- 文章[37] --