在C静态初始化结构 [英] static struct initialization in c

查看:106
本文介绍了在C静态初始化结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个结构键入如下所示:

I have a struct type as shown below:

typedef struct position{
    float X;
    float Y;
    float Z;
    float A;
} position;

typedef struct move{
    position initial_position;
    double feedrate;
    long speed;
    int g_code;
} move;

我想的静态初始化它,但我还没有找到一种方法来做到这一点。这可能吗?

I am trying to statically initialize it, but I have not found a way to do it. Is this possible?

推荐答案

它应该是这样的:

move x = { { 1, 2, 3, 4}, 5.8, 1000, 21 };

有关结构和数组的初始化括号可以嵌套。

The brace initializers for structs and arrays can be nested.

这篇关于在C静态初始化结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆