找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3708|回复: 6
收起左侧

关于单片机C语言预定义 #define u8 unsigned short;

[复制链接]
ID:712014 发表于 2020-4-11 15:55 | 显示全部楼层 |阅读模式
已经在主函数外预定义过u8就是unsigned short。为什么u8 number[10]会报错,而unsigned  short number[10]则没有问题。谢谢
#define u8 unsigned short;
u8 jian (void);
void main (void)
{
    unsigned short  number[10]={0x11,0x23,0x24,0x54,0x23,0x12,0x65,0x76,0x38,0x71};
回复

使用道具 举报

ID:10193 发表于 2020-4-11 17:27 | 显示全部楼层
语法错误,多了一个分号
回复

使用道具 举报

ID:155507 发表于 2020-4-11 17:48 | 显示全部楼层
#define u8 unsigned short;

你的定义有多余的分号
回复

使用道具 举报

ID:367369 发表于 2020-4-11 19:58 | 显示全部楼层
是不是u8在其他地方被宏定义了,你再定义就是重定义了,具体原因你得看报错是什么啊
回复

使用道具 举报

ID:727210 发表于 2020-4-11 22:42 | 显示全部楼层
别加分号,不然替换的时候会把分号一起加进去就出错了
回复

使用道具 举报

ID:592807 发表于 2020-4-13 08:40 | 显示全部楼层
你的宏定义后面加了分号,另外u8很多大佬在历程中宏定义为unsigned char,你定义unsigned short最好不要用u8。unsigned short 应该时是和int一样的16位的,你定义成u16

typedef unsigned          char u8;
typedef unsigned short     int u16;
typedef unsigned           int u32;
typedef unsigned       __INT64 u64;
                                               
typedef   signed          char int8_t;
typedef   signed short     int int16_t;
typedef   signed           int int32_t;
typedef   signed       __INT64 int64_t;

typedef unsigned          char uint8_t;
typedef unsigned short     int uint16_t;
typedef unsigned           int uint32_t;
typedef unsigned       __INT64 uint64_t;


回复

使用道具 举报

ID:712014 发表于 2020-4-13 15:56 | 显示全部楼层
黄youhui 发表于 2020-4-13 08:40
你的宏定义后面加了分号,另外u8很多大佬在历程中宏定义为unsigned char,你定义unsigned short最好不要用u ...

建议非常好,谢谢
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表