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]); }
