混合编译时所用宏__BEGIN_DECLS和__END_DECLS

宏定义内容:

sys/cdefs.h

/* C++ needs to know that types and declarations are C, not C++.  */
#ifdef	__cplusplus
# define __BEGIN_DECLS	extern "C" {
# define __END_DECLS	}
#else
# define __BEGIN_DECLS
# define __END_DECLS
#endif

一个语法糖,如果是在c++中,则__BEGIN_DECLS和__END_DECLS表示 extern "C" {},在C中,则表示无意义。

注:使 C 代码和 C++ 代码保持互相兼容的过程调用接口,需要在 C++ 代码里加上 extern “C” 作为符号声明的一部分

posted @ 2020-06-01 10:16  汪淼焱  阅读(823)  评论(0)    收藏  举报