在C中使用指定的初始化程序和Structs

 mobiledu2502939473 发布于 2023-02-09 08:13

我想测试一个非常简单的代码,但Visual Studio 2010没有编译它.这是我第一次使用带结构的指定初始化程序,但它似乎是100%正确的,因为它只是来自维基百科的简单复制和粘贴.

代码是:

#include 

/* 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功能吗?

1 个回答
  • Visual Studio 2010 c编译器仅支持C89.指定的初始化程序是C99功能.

    2023-02-09 08:16 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有