小编Con*_*mon的帖子

为什么我在尝试使用.c文件中的头文件时遇到类型错误?

我真的不明白这里发生了什么.我试图访问.c文件中的结构的成员,但是当我尝试访问struct变量时它给出了'error-type'.有人知道这里发生了什么吗?

CPU.h头文件:

#ifndef _CPU_H
#define _CPU_H

#include <stdint.h>

typedef struct cpu_registers
{
    union
    {
        struct
        {
            uint8_t f;
            uint8_t a;
        };
        uint16_t af;
    };
    union
    {
        struct
        {
            uint8_t c;
            uint8_t b;
        };
        uint16_t bc;
    };
} cpu_registers;

#endif /* _CPU_H */
Run Code Online (Sandbox Code Playgroud)

CPU.c文件:

#include "CPU.h"

cpu_registers regs;
regs.af = 0xFFFF;
Run Code Online (Sandbox Code Playgroud)

以下是使用clang编译时出现的错误:

CPU.c:4:1: error: unknown type name 'regs'
regs.af = 0xFFFF;
^
CPU.c:4:5: error: expected identifier or '('
regs.af = 0xFFFF;
    ^
2 errors generated.
Run Code Online (Sandbox Code Playgroud)

c struct

0
推荐指数
1
解决办法
63
查看次数

标签 统计

c ×1

struct ×1