Harsh Gupta Harsh Gupta - 2 months ago 6
C Question

Error C2660 : function does not take X arguments

I am converting some legacy C code to C++.

A header file contains a macro P

#ifndef P
# ifdef __STDC__
# ifndef __HIGHC__
# endif
# endif
# ifdef __sgi__
# endif

# define P(s) s
# else
# define P(s) ()
# endif

In my case the
evaluates to not defined.

Another header file uses the macro P in a function declaration.

extern void long2str P((unsigned char *str,int pos,long clong));

The function is then called at certain places in code like

long2str(tmp_str, 0, seg_used(seg)); // <= error on this line

However VS2012 flags error on lines where the function is called

error C2660: 'long2str' : function does not take 3 arguments

What could be going wrong?


Unless you are using a C compiler from the 1980s, you should make sure that the first branch of the #ifdef is taken.

In this case, find out why the USE_ANSI_PROTOTYPES is not defined. And then either define it or remove the #ifdef section and define the P macro unconditionally.

The Microsoft compiler doesn't define the __STDC__ macro (for whatever reason), see https://msdn.microsoft.com/en-us/library/b0084kay.aspx.


Back in the 1980 (before ANSI C89 and ISO C90), functions were declared like this:

extern void long2str ();

That's it. No parameter names, no types, just the function name (and if you are lucky, the return type).

ISO C90 introduced function prototypes, and the preferred way of declaring functions became:

extern void long2str (unsigned char *str,int pos,long clong);

The P macro from your question can produce both variants when it is called with the parameters in double parentheses. The outer parentheses form a single macro argument, and the inner parentheses are only needed in the C90 case.