Visual Studio2013的C语言编译器对C99标准的支持情况

Visual Studio2013终于开始比较良好地支持C99特性了。在此之前,如果用C语言写代码的话,变量名都需要放到函数体的前面部分,代码写起来十分别扭。

而Visual Studio2013中的C编译器已经支持了不少C99标准,让我来为大家盘点一下。

现在仍然不支持的语法特性有:

1、inline关键字:在VC中,仍然需要用微软自己定义的__inline,而尚不支持inline,尽管inline在C++中是支持的。

2、restrict关键字。

3、_Complex与_Imaginary:尽管VS2013的C语言编译器可以用complex.h库,不管这两个关键字不支持。库的实现用的是描述复数的结构体。

4、变长数组

除了上述四点,其它主要特性都予以了支持。下面给出一个示例代码来给出支持特性的描述:

#include <stdio.h>

#define MY_PRINT(...)   printf(__VA_ARGS__)

static __inline int MyGetMax(int x, int y)
{
    return x > y ? x : y;
}

int main(void)
{
    MY_PRINT("%s\n", "Hello, world!");

    int arr[] = { [0] = 100, [2] = 200, [8] = 400 };

    MY_PRINT("The value is: %d\n", arr[2] + arr[3]);

    struct Test
    {
        int x;
        float f;
        _Bool b;
        long long ll;
    
    }test = {.x = 10, .f = -0.5f, .b = 0};

    struct Test t = (struct Test){ .ll = 100LL };

    for (int i = 0; i < test.x; i++)
        t.x += test.x;

    int *p = (int[]){ [1] = t.x, [3] = test.b + test.ll };

    MY_PRINT("The value is: %d\n", p[0] + p[1] + p[2] + p[3]);
}

 

 

posted @ 2014-03-29 03:03  zenny_chen  Views(15539)  Comments(8Edit  收藏  举报