Visual C++ 2010/2008 does not accept `__int64` in C mode - c

I have reduced the problem to these lines:
typedef __int64 int64;
inline int64 qatoll(const char *nptr) { return _atoi64(nptr); }
When compiling in C mode with VC++2008 or 2010 I get errors:
t.c(2) : error C2054: expected '(' to follow 'inline'
t.c(2) : error C2085: 'qatoll' : not in formal parameter list
t.c(2) : error C2143: syntax error : missing ';' before '{'
In C++ mode it does accept the function definition and only complains about _atoi64.
What is the problem and how can I fix it?
Visual C++ 15 compiles it without errors, so is this related to C99 support?

It is not the __int64 which is the problem, but the inline syntax which should be _inline.
I just tried similar code on an older machine running MSVC 2008 to verify this.

Related

#include <dwrite.h> in C++ works, but not in C

A single-line test.c:
#include <dwrite.h>
From the visual studio command prompt,
compiled as C++ works: cl /c /Tp test.c
compiled as C does not: cl /c test.c
First, I get a bunch of errors as this one:
C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\um\dwrite.h(671): error C2059: syntax error: ':'
The line 671 is as follows:
interface DWRITE_DECLARE_INTERFACE("739d886a-cef5-47dc-8769-1a8b41bebbb0") IDWriteFontFile : public IUnknown
preprocessed to C++
struct __declspec(uuid("739d886a-cef5-47dc-8769-1a8b41bebbb0")) __declspec(novtable) IDWriteFontFile : public IUnknown
preprocessed to C
struct IDWriteFontFile : public IUnknown
and the part " : public IUnknown" gets in the way.
How am I supposed to fix this?
Then I get an error on line 1037: error C2061: syntax error: identifier 'IDWriteGeometrySink'
interface ID2D1SimplifiedGeometrySink;
typedef ID2D1SimplifiedGeometrySink IDWriteGeometrySink;
preprocessed to C
struct ID2D1SimplifiedGeometrySink;
typedef ID2D1SimplifiedGeometrySink IDWriteGeometrySink;
Finally, a bunch of errors involving static_cast which C does not have.
All in all, is dwrite.h not suitable for C? Using Visual Studio Community 2022. Does it work in any previous versions?
What I'm trying to do is compile https://github.com/makuke1234/PongD2D
C doesn't have inheritance, so this header is most likely C++ only.
The project you linked uses D2D from .cpp files and wraps C++ interface into C.

Build Apache APR 1.7 with Visual Studio (2017), IF_NAMESIZE undefined

Trying to build apr 1.7 on Windows with Visual Studio, tried 2017 and 2013.
When building the project (Debug|x86) or compiling e.g. dso.c if get the following error message:
1>dso.c
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2143: syntax error: missing ')' before '*'
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2143: syntax error: missing '{' before '*'
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2059: syntax error: ')'
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2061: syntax error: identifier 'apr_winapi_pfn_if_indextoname'
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2059: syntax error: ';'
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2513: ' ': no variable declared before '='
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2065: 'apr_winapi_pfn_if_indextoname': undeclared identifier
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): warning C4047: '=': 'int' differs in levels of indirection from 'int *(__cdecl *)(NET_IFINDEX,PCHAR)'
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2146: syntax error: missing ';' before identifier 'apr_load_dll_func'
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2100: illegal indirection
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2064: term does not evaluate to a function taking 1207 arguments
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): warning C4033: 'apr_winapi_if_indextoname' must return a value
I have succesfully build version 1.65 (after apply the hint from http://letcoderock.blogspot.com/2017/09/build-log4cxx-trunk-on-windows-by.html or Apache Cross Compilation Error ./gen_test_char: cannot execute binary file)
Comparing apr_arch_misc.h of the two version, i have noticed DLL_IPHLPAPI was new to the enum apr_dlltoken_e and Intelisense was complaining about
APR_DECLARE_LATE_DLL_FUNC(DLL_IPHLPAPI, PCHAR, NETIOAPI_API_, if_indextoname, 0, (
NET_IFINDEX InterfaceIndex,
PCHAR InterfaceName),
(InterfaceIndex, InterfaceName));
with "expecting a ')'".
If have changed NETIOAPI_API_ to WINAPI. Do not know if this is correct but the file could now be compiled (after running the above trick with gen_test_char.exe).
But after that I ran into the next Problem:
1>sockaddr.c
1>network_io\unix\sockaddr.c(144): error C2065: 'IF_NAMESIZE': undeclared identifier
1>network_io\unix\sockaddr.c(144): error C2057: expected constant expression
1>network_io\unix\sockaddr.c(144): error C2466: cannot allocate an array of constant size 0
1>network_io\unix\sockaddr.c(144): error C2133: 'scbuf': unknown size
1>network_io\unix\sockaddr.c(1274): error C2065: 'IF_NAMESIZE': undeclared identifier
I have succesfully build apr with gcc in linux/cygwin. I have looked into the the preprocessor substitutions for IF_NAMESIZE and here it is replaced by 44. But I can not find the definiton or where this is set.
Does anyone have an idea how to fix this? And is the above change to WINAPI correct?
Just use cmake to build the Visual Studio Solution:
With
cmake -G "Visual Studio 15 2017" -A x64
the .sln ist properly set up and building the solution works with no errors. Even gen_test_char.exe is build.
Maybe the apr project should make the cmake building instructions a little bit more prominent on their site.
As written in README file:
Note you must manually modify the include\apr.hw file before you
build to change default options
So i just removed line #define _WIN32_WINNT 0x0501 from apr-1.7.0\include\apr.hw
and run nmake -f Makefile.win. Worked fine for me. VS2017 tools, Windows 10.
In case someone else also runs into this problem: I was using cmake + nmake to build APR, but it still didn't work for me.
The reason was that I had old compilation flags to support Windows XP:
cmake -DMIN_WINDOWS_VER=0x0501 ...
Investigating Iphlpapi.h, it seems that netioapi.h and other networking headers used by the current version of APR are supported only starting from Vista onward:
#if (NTDDI_VERSION >= NTDDI_VISTA)
#include <netioapi.h>
#endif // (NTDDI_VERSION >= NTDDI_VISTA)
So in order for the compilation to work, just remove that cmake option or specify a value higher than 0x0600 (the equivalent for Vista).

error C2632: 'int' followed by 'bool' is illegal in VS 2015 (worked fine in VS 2013)

My Solution consists of Multiple C++ and one C project using VS 2015.
I am getting error error C2632: 'int' followed by 'bool' is illegal on following line of code in C header file.
#ifndef __cplusplus
typedef int bool;
#endif
this code was working fine in VS 2013
Any idea what could be the reason?

unscoped enums in C code with VS2015

I'm trying to compile the psutil module for Python, using VS 2015 and the Windows 10 SDK. Compilation fails with the following error:
c:\users\builder\documents\code\psutil\psutil\arch\windows\ntextapi.h(212): error C2365: 'ProcessBreakOnTermination': redefinition; previous definition was 'enumerator'
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\um\winternl.h(308): note: see declaration of 'ProcessBreakOnTermination'
c:\users\builder\documents\code\psutil\psutil\arch\windows\ntextapi.h(212): error C2086: '_PROCESSINFOCLASS2 ProcessBreakOnTermination': redefinition
c:\users\builder\documents\code\psutil\psutil\arch\windows\ntextapi.h(212): note: see declaration of 'ProcessBreakOnTermination'
Further investigation shows ProcessBreakOnTermination is part of an enum (PROCESSINFOCLASS) in winternl.h.
I believe this has to do with C++11's enforcement of scoped enums: https://msdn.microsoft.com/en-us/library/vstudio/2dzy4k6e(v=vs.110).aspx
However, I am lost on how to address this issue. If I try to add the class or struct bits as detailed on that MS website, I get compiler errors, since this is being compiled as C code. Why should the C++11 rules apply to C code here?
The solution I came up with was to wrap the offending dual-defined symbols in a #if.
(start of enum)
(last good entry)
#if _MSC_VER < 1900
(offending enum entry)
#endif
(next entry) = (last_good_entry)+2
Any nicer solutions are welcome!

Problems with running C code in Visual Studio Express 2012 [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I installed VS Express 2012 to learn C language in my University. I create new empty project then add new item to Source Files folder and change Source.cpp to Source.c
"Hello World" runs without problems but when I write simple "for" loop like this:
#include <stdio.h>
#include <stdlib.h>
int main() {
for (int i = 0; i <= 6; i++)
{
printf("the i value is: %d\n", i);
}
getchar();
return (0);
}
It writes me lots of errors:
------ Build started: Project: cTest, Configuration: Debug Win32 ------
Source.c
e:\ctest\source.c(7): error C2143: syntax error : missing ';' before 'type'
e:\ctest\source.c(7): error C2143: syntax error : missing ')' before 'type'
e:\ctest\source.c(7): error C2065: 'i' : undeclared identifier
e:\ctest\source.c(7): warning C4552: '<=' : operator has no effect; expected operator with side-effect
e:\ctest\source.c(7): error C2059: syntax error : ')'
e:\ctest\source.c(8): error C2143: syntax error : missing ';' before '{'
e:\ctest\source.c(9): error C2065: 'i' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Please help me solve this problem.
Shown in IdeOne,
error: ‘for’ loop initial declarations are only allowed in C99 mode
note: use option -std=c99 or -std=gnu99 to compile your code
I think, this clears your doubt. Declare i at the beginning of the function.
The correct code would be like this at WorkingExample.
From C99 Wiki, this is a new feature that was not available earlier.
Intermingled declarations and code: variable declaration is no longer
restricted to file scope or the start of a compound statement (block),
similar to C++
About VC++ compiler, direct from Mr. Herb Stutter's mouth,
Implements Standard C90 exactly (using /TC or naming files as
something.c)
This happens because your code does not obey to the current C standard under which you compile the code. Declaring int i for loop is allowed in C99 standard. Compile with -std=c99.

Resources