常见错误
C语言不支持函数重载
C11 新做法 —— 用 _Generic 伪装成重载
[1] 50344 segmentation fault ./a.out
int *p; // 不会分配地址空间?p是一个指针,里面的地址值是错误的
*p = 1;
printf("p=%d", *p);
bus error
struct Book
{
char title[50];
char author[20];
int book_id;
double price;
};
struct Book *pbook;
printf("%s", pbook->author);
strcpy(pbook->author, "Bangbang"); // bus error
char *name1 = "bang";
name1[2] = 'b'; //bus error
14659 segmentation fault
链接错误
ld: symbol(s) not found for architecture x86_64
$ cc myls.c
Undefined symbols for architecture x86_64:
"_err_quit", referenced from:
_main in myls-e331f1.o
"_err_sys", referenced from:
_main in myls-e331f1.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)