Error compiling ex_field_utils.c building vtk

I am using VS 2019 to build the vtk-9.3 source code I fetched from https://gitlab.kitware.com/vtk.
The errors are in line 30 of ex_field_utils.c"

static size_t my_strlcat(char *restrict dst, const char *restrict src, size_t maxlen)

|Error|C2061|syntax error: identifier ‘dst’
|Error|C2059|syntax error: ‘;’
|Error|C2059|syntax error: ‘,’
|Error|C2059|syntax error: ‘)’

My C++ knowledge is not sufficient to tell me what is wrong with this line.

The “restrict” keyword is a C keyword, but not a C++ keyword. The closest MSVC equivalent is “__restrict” with two underscores.

As you can see, David, I’m no C expert either. Can you tell me what the error is in line 30, and how to fix it?

VS 2019 doesn’t doesn’t recognize “restrict” so it reports a syntax error. If you replace restrict with __restrict, it should compile.

That worked.

Thanks.

Hi,

VS’s cl compiler has a C compiler, which is used when the source file ends with .c. So, changing restrict to __restrict signals something is amiss. You can get this specific line to compile, but you can stumble upon other problems such as C++ mangling symbols (in C it doesn’t happen).

So, I’d advise against tweaking C code just to be compilable by a C++ compiler. Instead, you should investigate why the C++ compiler is being called to compile C code, which is wrong. C code should be compiled with a C compiler and that’s that.

best,

PC

That’s above my pay-grade, Paulo. I’d assume that VTK developers, cmake and VS 2019 know how to ensure that the right compiler is used.

Cheers,

Gib

Yes, but with regards to restrict, the C compiler in VS2017 and VS2019 does not conform with C99. It’s not that the wrong compiler is being used, it’s that Visual Studio has a history of not supporting features of C unless those features also exist in C++.

Microsoft indeed has a decades-long history of some moronic decisions regarding its development tools. A proper, fully compliant C support in Windows can be found in MinGW64’s GCC if you’re willing to develop software written in C without issues. Either this or upgrade to VS 2022. I’ve just compiled VTK 9.3 with that version without any C syntax-related issues.

After fixing the “restrict” error the VTK build completed without problems. Onwards and upwards.