我正在查看vim源代码,特别是文件normal.c,我看到这个函数nv_operator正在使用,但它没有在任何地方定义(我grepped整个src目录)
它只被声明为:
static void nv_operator __ARGS((cmdarg_T *cap));
Run Code Online (Sandbox Code Playgroud)
我查了__ARGS的定义,但它只是......
在vim.h中没有(几乎没有):
#define __ARGS(x) x
Run Code Online (Sandbox Code Playgroud)
那么可能会发生什么?这是某种C创建虚拟函数的技术吗?
Joh*_*itb 11
这里有一个定义:
/*
* Handle an operator command.
* The actual work is done by do_pending_operator().
*/
static void
nv_operator(cap)
cmdarg_T *cap;
....
Run Code Online (Sandbox Code Playgroud)
这种定义方式是使用标识符列表作为参数.该样式已弃用(过时)但仍可在C中使用.标识符在参数列表中命名,其类型在紧跟函数声明符之后但在函数体之前的声明中命名.
该__ARGS宏是有处理的编译器不知道有关函数的原型(其他形式申报参数-类型和名称直接在函数参数列表相结合).据我所知,它在声明中根本不会发出任何参数.
更新:请参阅以下代码vim.h:
#if defined(MACOS) && (defined(__MRC__) || defined(__SC__))
/* Apple's Compilers support prototypes */
# define __ARGS(x) x
#endif
#ifndef __ARGS
# if defined(__STDC__) || defined(__GNUC__) || defined(WIN3264)
# define __ARGS(x) x
# else
# define __ARGS(x) ()
# endif
#endif
Run Code Online (Sandbox Code Playgroud)