前两天看程序,发现在某个函数中有下面这段程序: int n; //define a variable n int array[n]; //define an array with length n 在我所学的C语言知识中,这种数组的定义在编译时就应该有问题的,因为定义数组时,数组的长度必须要是一个大于0的整型字面值或定义为 const 的常量.例如下面这样 int array1[10]; //valid int const N = 10; int array2[N]; //valid int n
GCC中的弱符号与强符号 我们经常在编程中碰到一种情况叫符号重复定义.多个目标文件中含有相同名字全局符号的定义,那么这些目标文件链接的时候将会出现符号重复定义的错误.比如我们在目标文件A和目标文件B都定义了一个全局整形变量global,并将它们都初始化,那么链接器将A和B进行链接时会报错: 1 b.o:(.data+0x0): multiple definition of `global' 2 a.o:(.data+0x0): first defined here 这种符号的定义可以被称为强符
— Built-in Function: void * __builtin_return_address (unsigned int level) This function returns the return address of the current function, or of one of its callers. The level argument is number of frames to scan up the call stack. A value of 0 yield
正常情况下,编译器都会报错,提示你有两个候选类,让你明确的选择一个. 比如我的情况,我自己设计了一个类Message, 然后在某个文件里面引用了它.但是我的文件中又引入了mongodb的头文件,非常不小心的用 using namespace mongo; 打开了名字空间.结果两个类Message之间冲突. 当编写代码 Message* p = NULL; 得到GCC4.8.1的友好的编译错误: error: reference to ‘Message’ is ambiguous 但是如果写成这样