C/C++

在所有高级编程语言中,只有C和Non-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!C包办了寄存器分配和调用栈管理...

tang_yuan.png

++ii++i+=N的汇编一样,是否比i=i+1i=i+N快,就看编译器了,反正gcc编译后用objdump反汇编,指令都一样(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 c?t:f, 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.

=赋值与接口调用时的传参,都存在Implicit Conversion的可能!

有两种Right Shift操作,Logical和Arithmetic。前者补0,后者补MSB。基本上所有编译器都选择,signed右移采用后者,unsigned右移采用前者。Left Shift操作只有一种,补0。

malloc后new后检查free后delete后赋NULL或nullptr(防止double free,减少dangling pointer),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,它由编译器在编译期计算得到。

Wild Pointer: is a pointer that has not been correctly initialized and therefore points to some random piece of memory.

Dangling Pointer: is a pointer that used to point to a valid address but now no longer does. This is usually due to that memory location being freed up and no longer available.

得到.o文件有多种方式:(1)编译.c文件;(2)编译.s文件;(3)objcopy创建。

为什么变量名不可以用数字开头?因为存在这些合法literal形式:1234U2345L...

-- 目录[2] --

-- 文章[37] --