none
stdio.h errors in Visual Studio 2005

    Question

  • I just finished installing VS 2005 (is it that hard for microsoft to just let people download like, a zip file of it, rather than an img file, which i had no idea what to do with at first?) and tried the following code:

    #include <stdio.h>    // include the standard input/output header file

    void main(void)    // our program starts here
    {
        printf("Hello World!");    // print "Hello World!" into the console
        return;    // return void to windows
    }

    It was part of an origionally blank win32 console app called test.  When i tried building the solution or compiling the file separately, I got all those errors:

    ------ Build started: Project: Test, Configuration: Debug Win32 ------

    Compiling...

    Main.cpp

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(221) : error C2373: '__restrict__' : redefinition; different type modifiers

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(221) : see declaration of '__restrict__'

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(224) : error C2086: 'const char *__restrict__' : redefinition

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(223) : see declaration of '__restrict__'

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(439) : error C2143: syntax error : missing ';' before '__cdecl'

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(439) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(439) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(440) : error C2143: syntax error : missing ';' before '__cdecl'

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(440) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(440) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(441) : error C2143: syntax error : missing ';' before '__cdecl'

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(441) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(441) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(471) : error C2373: '__restrict__' : redefinition; different type modifiers

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(470) : see declaration of '__restrict__'

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(473) : error C2086: 'const wchar_t *__restrict__' : redefinition

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(472) : see declaration of '__restrict__'

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(489) : error C2143: syntax error : missing ';' before '__cdecl'

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(489) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(489) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(490) : error C2143: syntax error : missing ';' before '__cdecl'

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(490) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(490) : warning C4229: anachronism used : modifiers on data are ignored

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(490) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(495) : error C2143: syntax error : missing ';' before '__cdecl'

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(495) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(495) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(496) : error C2143: syntax error : missing ';' before '__cdecl'

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(496) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(496) : warning C4229: anachronism used : modifiers on data are ignored

    c:\program files\microsoft visual studio 8\vc\include\stdio.h(496) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    Build log was saved at "file://c:\Program Files\Game_Stuff\Test\Test\Debug\BuildLog.htm"

    Test - 25 error(s), 2 warning(s)

    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    I want to be able to use directx, and from what I hear VS 2005 should work (unfortunately, devcpp doesn't), but if it can't even print a few words, I don't even want to bother yet. So, any help on how to fix this is appreciated.

    Tuesday, February 20, 2007 5:23 PM

Answers

  • I think you're gonna have to reinstall VS2005.  Your headers look like MING stuff (a Win32-GCC thing)
    Friday, February 23, 2007 1:03 AM
    Moderator

All replies

  • is there any chance you used C++.Net wizard to create the project
    Tuesday, February 20, 2007 9:00 PM
  • I have a feeling you are using the Express edition. This one does not come with Platform SDK installed and you cannot develop MFC or ATL applications with it. So, in order to do DirectX programming, you have to install the SDK first.

    Second, are you writing code in C or C++? Anyway, in both languages, the main() function returns int not void.

    Wednesday, February 21, 2007 7:01 AM
  • It's a c++ file, and i'm aware main returns an int, but I just copy+pasted it from a site anyway.

    And I am almost completely sure i'm not running the express version. I downloaded the 90 day trial version of Visual Studio 2005, and I ran devenv.exe under "\Microsoft Visual Studio 8\Common7\IDE\". I don't have a clue where the platform sdk is (or what it is for that matter) so maybe if someone told me i could check that.

    Wednesday, February 21, 2007 7:39 PM
  • Probably some compiler setting from somewhere else that is in conflict.  Instead of trying to guess, how about if you create a project from scratch:

    1. Choose New Project, Visual C++, Win32, Win32 Console Application. Hit Finish.

    2. Replace the _tmain definition with:

    #include <stdio.h> // include the standard input/output header file
    int main() // our program starts here
    {
      printf(
    "Hello World!"); // print "Hello World!" into the console
      return 0;
    }


     

    Wednesday, February 21, 2007 7:53 PM
    Moderator
  • Nope. I just get the same set of errors I did last time. Even with the exact thing the project gives me, I get those errors. For some reason it can't compile stdio.h...

    Thursday, February 22, 2007 3:36 PM
  • what does you include path looks like?
    Thursday, February 22, 2007 3:46 PM
  • Go to the C/C++ project settings (under project properties), go to the command line section, and add /Bd. This will output all the compiler flags, including the include paths.  Paste it here.

    Thanks.

    Thursday, February 22, 2007 3:51 PM
    Moderator
  • I assume you mean this:

    `C:\Program Files\Microsoft Visual Studio 8\VC\bin\c1xx.dll -zm0x79600000 -il C:\DOCUME~1\OREILL~1\LOCALS~1\Temp\_CL_13e4e036 -f .\stdafx.cpp -Ze -D_MSC_EXTENSIONS -Zp8 -ZB64 -D_INTEGRAL_MAX_BITS=64 -Gs -pc \:/ -D_MSC_VER=1400 -D_MSC_FULL_VER=140050727 -D_WIN32 -D_M_IX86=600 -D_M_IX86_FP=0 -GS -GR -D_CPPRTTI -Zc:forScope -Zc:wchar_t -Ot -DWIN32 -D_DEBUG -D_CONSOLE -D_UNICODE -DUNICODE -Gm -EHs -D_CPPUNWIND -EHc -D__MSVC_RUNTIME_CHECKS -RTCs -RTCu -D_DEBUG -D_MT -D_DLL -Ycstdafx.h -FpDebug\Test2.pch -FoDebug\stdafx.obj -FdDebug\vc80.pdb -W 3 -D_Wp64 -Wp64 -ZI -FC -GF -Zi -FD -Bd -nologo -errorreport:prompt -I C:\Program Files\Microsoft Visual Studio 8\VC\include -I C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include -I C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include -I C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\include'

    The rest was just the same errors I get every time.

    Thanks for your time and effort.

    Thursday, February 22, 2007 8:18 PM
  • try without -D_MSC_EXTENSIONS
    Thursday, February 22, 2007 9:43 PM
  • My -Bd output is the same except for one include path (highlighted). Try deleting it.

    Mine:

    -I C:\Program Files\Microsoft Visual Studio 8\VC\include

    -I C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include

    -I C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include

    -I C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\include

    Yours:

    -I E:\Program Files\Microsoft Visual Studio 8\VC\include

    -I E:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include

    -I E:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include

    -I E:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\common\include

    -I E:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\include

     

    Thursday, February 22, 2007 10:06 PM
    Moderator
  • Actually, I think you have it mixed around. I only have the four on top. Plus, mine is installed on the C drive. But I tried adding the common/include and it didn't work with that either.
    Thursday, February 22, 2007 11:36 PM
  • Whoops, you're right.  In any case, our compiler flags match up exactly.  One difference i notice between our respective stdio.h that my line 221 (where the first error occurs) is empty.  Here are lines 216-216 of my copy of stdio.h:

    216: #ifdef _POSIX_
    217: _CRTIMP __checkReturn int __cdecl fileno(__in FILE * _File);
    218: #else
    219: _CRTIMP __checkReturn int __cdecl _fileno(__in FILE * _File);
    220: #endif
    221:
    222: #if
    defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
    223: #pragma push_macro("_tempnam")
    224: #undef _tempnam
    225: #endif

    Check your stdio.h lines 216-225. 

    You can give me your preprocessed stdafx.cpp (thats were your error occurs), and email it to me.  Set the compiler flag /P (under the same place you threw /Bd) , compile, find the resulting file stdafx.i, and attach the file in a mail to my address: kramer_ae AT hotmail DOT com

    Also give me your stdio.h.

    I'm guessing that someone copied over a GCC version of the standard headers and placed them under the VC8 directory.  This is a weak guess, because such a move should always be disasterous. 

    Based on some google hits, I think __restrict__ is a GCC-specific extension that means the same thing as the Microsoft-specific extension __restrict (this is documented in MSDN).  But I wouldn't want to suggest a workaround until we determine that your headers are kosher.

    Brian

    Friday, February 23, 2007 12:13 AM
    Moderator
  • in my stdio.h (the VC\include\ one), its:

    #ifndef __NO_ISOCEXT /* externs in libmingwex.a */

    int __cdecl snprintf(char* s, size_t n, const char* format, ...);

    __CRT_INLINE int __cdecl

    vsnprintf (char* s, size_t n, const char* format, __VALIST arg)

    { return _vsnprintf ( s, n, format, arg); }

    int __cdecl vscanf (const char * __restrict__, __VALIST);

    int __cdecl vfscanf (FILE * __restrict__, const char * __restrict__,

    __VALIST);

    int __cdecl vsscanf (const char * __restrict__,

    const char * __restrict__, __VALIST);

    #endif

    starting at line 215... and yeah, i'll work on sending you that stuff.

    Friday, February 23, 2007 12:37 AM
  • I think you're gonna have to reinstall VS2005.  Your headers look like MING stuff (a Win32-GCC thing)
    Friday, February 23, 2007 1:03 AM
    Moderator
  • Well that kinda sucks, but thanks anyway. 
    Friday, February 23, 2007 1:09 AM
  • In case any one else has encountered this and still needs a solution.  May be caused by the project settings.  By default Managed Build is enabled.  Instead turn this feature off.  Open Project properties.  Go to Configuration Properties\General set Enable Managed Incremental Build = No

     

    Thursday, July 28, 2011 8:43 PM
  • Maybe you include the compiler defininition for the Variable __NO_ISOCEXT through the project->Properties->Compiler->Preprocessor.

     

    You may also encounter same problem after this. This time you may need to define the variable __NO_INLINE__ the same way.

    Tuesday, September 13, 2011 7:49 AM
  • have you tried adding

    #define WINN32_LEAN_AND_MEAN

    at the top of stdafx.h or the c/cpp file generating the error?

    For some MS defined types it worked well for me.


    dm

    Friday, December 12, 2014 3:39 PM