Friday, January 10, 2014

Visual Studio 2013 - C99 support

I think using C99 in game development could be useful for large teams, especially if they are distributed over several locations.
So I thought I look a little bit closer on the support of C99 in Visual Studio 2013 (we also use VS 2013 with C99 now in my UCSD class).
The new features that are support in VS 2013 are:

New features in 2013
- variable decls
- _Bool
- compound literals
- designated initializers

Already available:
variadic macros, long long, __pragma, __FUNCTION__, and __restrict

What is missing:
- variable-length arrays (VLAs)
- Reserved keywords in C99
C99 has a few reserved keywords that are not recognized by C++:
restrict
_Bool -> this is now implemented ... see above
_Complex
_Imaginary
_Pragma
- restrict keyword
C99 supports the restrict keyword, which allows for certain optimizations involving pointers. For example:

    void copy(int *restrict d, const int *restrict s, int n)
    {
        while (n-- > 0)
            *d++ = *s++;
    } 
C++ does not recognize this keyword.
A simple work-around for code that is meant to be compiled as either C or C++ is to use a macro for the restrict keyword:

    #ifdef __cplusplus
     #define restrict    /* nothing */
    #endif 
(This feature is likely to be provided as an extension by many C++ compilers. If it is, it is also likely to be allowed as a reference modifier as well as a pointer modifier.)

Don't know if it is in there:
- hexadecimal floating-point literals like 
float  pi = 0x3.243F6A88p+03; 
- C99 adds a few header files that are not included as part of the standard C++ library, though:
<complex.h>
<fenv.h>
<inttypes.h>
<stdbool.h>
<stdint.h>
<tgmath.h>


References



3 comments:

  1. Is this a petition? If so, I'm signing it!

    -- Mike Acton, Engine Director, Insmoniac Games

    ReplyDelete
  2. +1 for c99 support

    ( note that they have their c/c++ __restrict http://msdn.microsoft.com/en-us/library/5ft82fed.aspx own restrict equivalent)

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete