是否可以为头文件中声明的相同函数提供2个(或更多)不同的实现?我举一个例子-假设我们有一个名为一个头文件common.h和2个名为源文件src1.c和src2.c.
//lots of common function declarations implemented in some file common.c
int func(int a, int b);
Run Code Online (Sandbox Code Playgroud)
#include "common.h"
int func(int a, int b)
{
return a+b;
}
Run Code Online (Sandbox Code Playgroud)
#include "common.h"
int func(int a, int b)
{
return a*b;
}
Run Code Online (Sandbox Code Playgroud)
假设我希望每个源文件都使用其本地版本func().有可能这样做吗?