【发布时间】:2014-07-30 14:30:25
【问题描述】:
考虑一个 C++ 函数,我想在 C 中接口它(例如,int foo()),它不接受输入参数。
C 中缺少输入参数可以表示为int foo(void);,而C 中的int foo() 表示任意数量的输入参数。
但是,在 C++ 中,int foo() 表示不带参数的函数,int foo(void) 被视为应避免的 C 向后兼容残余。
考虑到上述情况,什么是最合适的?
选项 1:
C 头声明:
int foo(void);C++ 文件定义:
int foo(void) { ... }选项 2:
C 头声明:
int foo();C++ 文件定义:
int foo() { ... }选项 3:
C 头声明:
int foo(void);C++ 文件定义:
int foo() { ... }
【问题讨论】: