Locked ANSI C Comaptibility

  • Thursday, March 08, 2012 4:35 PM
     
     

    I need a compiler that is ANSI C compatible for another program that I am using.  The developers of this other program have a test for whether the the compiler is ANSI C compliant.  The snippet below is compiled and run, and the answer appears in the console window.

    #ifdef __STDC__
    printf (“The compiler used to compile this code supports ANSI\n”);
    #else
    printf (“The compiler used to compile this code is non-ANSI\n”);
    #endif
    }

    Of course, Visual Studio Express 2010 fails this test.  However, I was told by the on-line chat folks at Microsoft that it was ANSI C compliant.  Does anyone know if the problem is just some configuration setting that I need to change?  (Or is it really true that Microsoft Visual Studio Express has no <String.h> header file, like the error message I keep getting when I use this other program suggests?)

All Replies

  • Thursday, March 08, 2012 8:58 PM
     
     Answered
    >Or is it really true that Microsoft Visual Studio Express
    >has no <String.h> header file, like the error message I
    >keep getting when I use this other program suggests?

    There is a header named string.h in VC++ and in ANSI C.

    If you are getting an error from an #include you need to
    show the exact error message and the exact code.

    >#ifdef __STDC__
    >Visual Studio Express 2010 fails this test.

    VC++ recognizes that predefined macro (manifest constant).
    However, it is only defined when you build with the option
    enabled to disable MS extensions. See:

    Predefined Macros
    http://msdn.microsoft.com/en-us/library/b0084kay%28v=vs.100%29.aspx

    /Za, /Ze (Disable Language Extensions)
    http://msdn.microsoft.com/en-us/library/0k0w269d.aspx

    >I was told by the on-line chat folks at Microsoft that
    >it was ANSI C compliant.

    It is compliant with the ANSI/ISO C90 Standard.

    - Wayne
    • Proposed As Answer by Crescens2k Friday, March 09, 2012 1:33 PM
    • Marked As Answer by Rob PanModerator Monday, March 19, 2012 8:48 AM
    •  
  • Friday, March 09, 2012 1:33 PM
     
     Answered Has Code

    In addition to what Wayne said, you can check what headers VC is shipped with yourself. They are in the VC directory itself.

    By default this is %ProgramFiles%\Visual Studio 10.0\VC\include (this is %ProgramFiles(x86)% on 64 bit versions of Windows).

    If you also want to test out whether it has this header, you can also just do a simple test application along the lines of:

    #include <string.h>
    int main()
    {
        return 0;
    }

    and try to build it. Because of the entry point being main, this obviously requires a console application, but if this fails to compile because it can't find the header string.h then I would urge you to check your configuration.


    This is a signature

    Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    Do you want Visual Studio 11 Express to be freely installable on Windows 7 and able to write regular C++ applications? Please vote for this.