C:typedef联合 [英] C: typedef union

查看:119
本文介绍了C:typedef联合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在相关问题中找不到任何内容.很有可能是超级菜鸟,但无论如何我都会问/我的.h文件中包含以下内容:

didn't find anything in related questions. Most probably it's super noob, but I'll ask anyway/ I've got the following in my .h file:

typedef union _API_Packet_0x90{
    uint8_t packet[26];
    struct _pack_struct {
        uint8_t start;
        uint8_t length[2];
        uint8_t addr64[8];
        uint8_t addr16[2];
        uint8_t options;
        uint8_t rfData[4];
        uint8_t chksum;
    };
} API_Packet_0x90;

API_Packet_0x90 ap90;

这是微控制器的代码,我使用的是xc8工具链(以前的Hi Tech C).编译器说:

This is code for a microcontroller, I'm using xc8 toolchain (former Hi Tech C). The compiler says:

xbee_api.h:19:警告:缺少基本类型;假定为int
xbee_api.h:19: 错误: ";"预期
xbee_api.h:19:警告:缺少基本类型;假定为int
xbee_api.h:21:警告:缺少基本类型;假定为

xbee_api.h:19: warning: missing basic type; int assumed
xbee_api.h:19: error: ";" expected
xbee_api.h:19: warning: missing basic type; int assumed
xbee_api.h:21: warning: missing basic type; int assumed

,然后继续(错误太多)

, and this goes on (too many errors)

我以为是uint8_t,因此添加了#include <ctypes.h>.没有.我以为这是关于名字的,所以我尝试了各种戏剧,例如

I thought it's uint8_t, so I added #include <ctypes.h>. Nope. I thought it is about names, so I tried all kinds of plays such as

typedef union {
    uint8_t packet[26];
    struct _pack_struct {

    };
} API_Packet_0x90;

typedef union {
    uint8_t packet[];
    struct _pack_struct {

    };
} API_Packet_0x90;

或其他.没有任何帮助.我被困住了,因为我相信自己正确地遵循了语法.有帮助吗?

or others. Nothing helps. I'm stuck as I believe I'm following syntax properly. Any help?

推荐答案

uint8_t位于stdint.h中,而不是在ctype.h中(也不存在ctypes.h,不存在这样的标头).您必须使用遵循更高版本C标准的编译器才能找到此标头(C99或C11标准).

uint8_t is located in stdint.h, not in ctype.h (nor ctypes.h, no such header exists). You must use a compiler that follows a newer version of the C standard for this header to be found (C99 or C11 standards).

这篇关于C:typedef联合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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