你可以做這樣的事情:
#define get_resolution __mock_get_resolution
地方全局訪問(例如標題,你總是包含等),然後執行以下操作:
#undef get_resolution
void get_resolution()
{
}
#define get_resolution __mock_get_resolution
void display()
{
get_resolution();
}
醜陋的黑客攻擊,而且可以節省你必須寫一個sed(1)腳本。
測試用例如下:
$ gcc -o test test.c
$ ./test
__mock_up
$ cat test.c
#include <stdio.h>
#define get_resolution __mock_up
int
__mock_up()
{
printf("__mock_up\n");
}
#undef get_resolution
int
get_resolution()
{
}
#define get_resolution __mock_up
int main()
{
get_resolution();
return 0;
}
$