C/C++

在所有的编程语言中,只有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!

tang_yuan.png

++ii++i+=N的汇编一样,是否比i=i+1i=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

floatdouble浮点型数据,也可以执行++--,但不推荐,也较危险!(浮点数

用哪个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, then n>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.

-- 目录[2] --

-- 文章[35] --