找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3139|回复: 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};
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
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在其他地方被宏定义了,你再定义就是重定义了,具体原因你得看报错是什么啊
回复

使用道具 举报

5#
ID:727210 发表于 2020-4-11 22:42 | 只看该作者
别加分号,不然替换的时候会把分号一起加进去就出错了
回复

使用道具 举报

6#
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;


回复

使用道具 举报

7#
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 单片机教程网

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