C/C++
没啥好说的
蜗牛世家
什么时候才能年入百万,嗯哼,不存在的
展开
-
extern “c“的含义
extern “c”是为了在c++程序中引用c程序。 比如有如下3个文件 /*my_c.h*/ int add(int a,int b); /*my_c.c*/ int add(int a,int b) { return a+b; } /*main.cpp*/ int main() { int all=add(1,2); } 如果编译的话,会用gcc编译my_c.o,g++编译main.o,在main.o链接my_c.o时会找不到add函数的符号表,如下图所示: main.o中采用g++编译.原创 2021-08-10 11:03:53 · 144 阅读 · 0 评论 -
#ifdef问题
在代码中多次使用#ifdef会报一个warning:extra tokens at end of #ifdef directive,比如下面这样: #ifdef a ...... #endif #ifdef b ...... #endif 如果想检查多个条件,可以这样写: #if defined a ...... #endif #if defined b ...... #...原创 2018-12-18 14:26:36 · 1642 阅读 · 0 评论 -
c语言野指针的一个注意事项
typedef struct{ int* data; }test; int main(){ test* L; L->data=(int*)malloc(sizeof(int)*20); } 上面这样写会报段错误,因为L是个野指针,指向未知的地址,可以修改为 test* L; L=(test*)malloc(sizeof(test));//给L也分配内存空间 L...原创 2018-12-18 13:54:02 · 156 阅读 · 0 评论