小编Ale*_*les的帖子

Why can't you define struct members globally?

When you define a struct globally, why can't you define the structure members globally as well (outside of using the initializer syntax)? The error I'm getting from clang is that system_1 has an "unknown type name".

If you define the struct within a function, such as main(), then you don't run into any issues.

typedef struct Light_System {
    int redLightPin;
    int yellowLightPin;
    int blueLightPin;
} Light_System;

Light_System system_1;

# "Light_System system_1 = {4, 0, 0}" works

system_1.redLightPin = 4; …
Run Code Online (Sandbox Code Playgroud)

c struct

2
推荐指数
1
解决办法
82
查看次数

标签 统计

c ×1

struct ×1