http://www.sanfoundry.com/cpp-program-find-closest-pair-points-array/ I can run this without any errors in mingw c++ but with so many errors in visual c++ 2013. why?
Asked
Active
Viewed 313 times
-2
-
Please describe which steps you took when you attempted to compile the code in Visual C++, and provide a sample of the errors reported. – Ole Wolf Nov 28 '17 at 07:26
1 Answers
3
First, they use two different C/C++ compiler - Microsoft C/C++ Compiler and GCC.
Your sample use Variable-length array like here.
float closestUtil(Point Px[], Point Py[], int n)
{
...
int mid = n / 2;
...
Point Pyl[mid + 1];
Point Pyr[n - mid - 1];
...
}
Programming languages that support VLAs include Ada, Algol 68 (for non-flexible rows), APL, C99 (although subsequently relegated in C11 to a conditional feature which implementations are not required to support; on some platforms, could be implemented previously with alloca() or similar functions)
-- variable-length array on wikipedia.org
The Microsoft compiler do not support Variable-length array[1] (is not C99 compliant[2]) and GCC support it as and extension[7].
To solve this you can replace them with std::vector
.
You can turn the GCC warnings as explained here.

Mihayl
- 3,821
- 2
- 13
- 32