2013-12-20 52 views
2

我想測試一個非常簡單的代碼,但Visual Studio 2010未編譯它。這是我第一次使用帶有結構的指定初始值設定項,但它看起來是100%正確的,因爲它只是從wikipedia進行的簡單複製和粘貼。在C中使用帶有Structs的指定初始化程序

的代碼是:

#include <stdio.h> 

/* Forward declare a type "point" to be a struct. */ 
typedef struct point point; 
/* Declare the struct with integer members x, y */ 
struct point { 
    int x; 
    int y; 
}; 

/* Define a variable p of type point, and set members using designated initializers*/ 
point p = {.y = 2, .x = 1}; 

int main() 
{ 
    point p2 = {.y = 3, .x = 4}; //not even inside main it works 
    return 0; 
} 

的Visual Studio標誌着.Y點爲紅色。有誰知道發生了什麼事?我在互聯網上搜索了其他參考資料,我看不出爲什麼我的代碼是錯誤的。 VS2010不支持C功能嗎?

+2

指定的初始值設定項僅在VS2013之後可用。 –

回答

10

Visual Studio 2010 c編譯器僅支持C89。指定的初始化程序是一個C99功能。

+2

真的嗎?!那麼微軟14年來遵守標準呢?哈哈 – mFeinstein

+3

即使現在他們仍然只有部分C99的支持。 –

相關問題