Function prototypes without argument name and function declaration without data type in Visual Studio

321 Views Asked by At

Good afternoon,

I've been tasked with implementing code that seems to have been written for C99 in Visual Studio 2010. I've researched numerous C99/Visual Studio compatibility threads, but I haven't found anything relating to fixing my issue.

Basically, the code I have to port has function prototype and declaration written in the following way:

void myfunc(int, char*); //Prototype

void myfunc(variable1, pointer1) //Declaration
{
   ;//...
}

But Visual Studio 2010 is only willing to accept

void myfunc(int variable1, char* pointer1); //Prototype

void myfunc(int variable1, char* pointer1) //Declaration
{
   ;//...
}

I'm not 100% sure if this is even a C99 compatibility issue or some outdated coding practice, but the source file is being constatly updated by a third party and it's a requirement for me to avoid changing anything in it (such as renaming each single function), it is also a requirement for me to use visual studio 2010 because of a plug-in compiler. Is there an option that may allow this style of function declarations?

Thank you,

2

There are 2 best solutions below

2
On

As far as I know MS VC++ does not support C99.

As for the function definition thsi definition

void myfunc(variable1, pointer1) //Declaration
{
   ;//...
}

is invalid even for C89. After this header

void myfunc(variable1, pointer1)

and before the opening brace there shall be identifier declarations. If these declarations are present and you made simply a typo then you can use MS VC++ 2010. But you have to compile the code as C code.

According to the C Standard

6 If the declarator includes an identifier list, each declaration in the declaration list shall have at least one declarator, those declarators shall declare only identifiers from the identifier list, and every identifier in the identifier list shall be declared. An identifier declared as a typedef name shall not be redeclared as a parameter. The declarations in the declaration list shall contain no storage-class specifier other than register and no initializations.

0
On

This is a difference between C and C++.

In fact, in C++, please see my corrected annotations below:

void myfunc(int variable1, char* pointer1); // Declaration

void myfunc(int variable1, char* pointer1)  // Definition
{
   // ...
}