1

I am working on porting c code to c++. The below C program compiles successfully. But in c++, it throws an error. I know its really basic thing. I've more than 100 functions declared in this way. Is there any flag we can add to compile successfully instead of modifying all the functions.

  • OS: Windows
  • IDE: Visual Studio
int sum(m,n)
int m,n;
{
    return m+n;
}
Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
  • You might look at some *"reformater"* tools to automatise the process. I don't know if *clang-tidy*/*clang-format* supports that notation though. – Jarod42 Mar 01 '21 at 10:54

1 Answers1

5

This is very old style C. Nobody should have been using this for the last 30 years. You can't compile this with a C++ compiler. There are no compiler flags whatsoever for this, at least in the compilers I'm aware of (clang, gcc, microsoft compilers).

You should transform all functions that have the form

int sum(m,n)
int m,n;
{
    return m+n;
}

int to the form

int sum(int m, int n)
{
    return m+n;
}

If you have 100 functions it should be doable. But there may be many other problems because C++ is not an exact superset of C.

This SO article may be interesting for you: Function declaration: K&R vs ANSI

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
  • I think you have a small typo: `int sum(int m, _int_ n)`. But +1 for teaching me about K&R function declaration style. :) – Frodyne Mar 01 '21 at 10:58