Function C, it would seem, is not defined anywhere!

I look at the vim source code, in particular the normal.c file, and I see that this nv_operator function nv_operator used, but it is not defined anywhere (I grepped the entire src directory)

It is declared only as:

 static void nv_operator __ARGS((cmdarg_T *cap)); 

I was looking for the definition of __ARGS, but it's just ... nothing (pretty much)
in vim.h :

 #define __ARGS(x) x 

So what could be? Is this some kind of C method for creating a dummy function or something else?

+4
source share
4 answers

It is difficult to find because of how it is defined:

nv_operator (cover)

appears on a separate line.

+1
source

There is a definition here:

 /* * Handle an operator command. * The actual work is done by do_pending_operator(). */ static void nv_operator(cap) cmdarg_T *cap; .... 

This definition style uses a list of identifiers for its parameters. The style is deprecated (deprecated), but can still be used in C. Identifiers are named in the parameter list, and their type is indicated in declarations that immediately follow the function declarator but precede the function body.

The __ARGS macro must be processed by compilers that are not aware of prototypes for functions (another form for declaring parameters is with a type and name combined directly in the function parameter list). I think, then, he simply did not give out any parameters in the declarations.

Update: see this code in vim.h :

 #if defined(MACOS) && (defined(__MRC__) || defined(__SC__)) /* Apple 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 
+11
source

This is just a forward declaration , so the function is known to the C compiler (and can be used (called from other functions)) before it is actually defined (on line 8247). Actual formatting of the definition (including newlines) makes it difficult to exist.

Do not be distracted by the __ARGS macro. This is just a compatibility macro for the syntax for declaring various K & RC functions compared to ANSI C.

In ANSI C, a function declaration should look like this:

int getopt (int, char * const *, const char *);

In (older) Kernighan and Ritchie C http://en.wikipedia.org/wiki/C_(programming_language)#K.26R_C

int getopt ();

+2
source

I'm not too sure what is going on, but here are some tips to help you in your search:

First of all, the __ARGS macro seems to exist, because there may be versions of C where you should not include arguments in the function declaration (note that the macro is defined differently depending on other preprocessor characters. In the comments say).

Secondly, finding the nv_operator function may not be good enough. The function can be generated by macros, etc., so you cannot look for an explicit definition .... for example, perhaps the prefix "nv" is added by the preprocessor.

Hope this helps.

+1
source

All Articles