野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 18739|回复: 3

求助 为啥 else 后的语句无分号?

[复制链接]
发表于 2013-8-8 22:24:39 | 显示全部楼层 |阅读模式
这是配套程序,为啥 else 后的语句无分号?

#ifndef __LED_H
#define __LED_H
#include "stm32f10x.h"
/* the macro definition to trigger the led on or off
* 1 - off
- 0 - on
*/
#define ON  0
#define OFF 1
//带参宏,可以像内联函数一样使用
#define LED1(a) if (a) \
     GPIO_SetBits(GPIOC,GPIO_Pin_3);\
     else  \
     GPIO_ResetBits(GPIOC,GPIO_Pin_3)       //????????????
#define LED2(a) if (a) \
     GPIO_SetBits(GPIOC,GPIO_Pin_4);\
     else  \
     GPIO_ResetBits(GPIOC,GPIO_Pin_4)
#define LED3(a) if (a) \
     GPIO_SetBits(GPIOC,GPIO_Pin_5);\
     else  \
     GPIO_ResetBits(GPIOC,GPIO_Pin_5)
void LED_GPIO_Config(void);
#endif /* __LED_H */

回复

使用道具 举报

发表于 2013-8-8 22:31:01 | 显示全部楼层
可能是因为宏定义吧
回复 支持 反对

使用道具 举报

发表于 2013-8-8 22:34:58 | 显示全部楼层
因为在使用宏LED1(a)的时候,大家一般习惯性地当它是函数来用,会在LED1(a)后面加一个分号,所以宏定义的时候就不加了
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-8-9 09:01:04 | 显示全部楼层
恩,谢谢。
回复 支持 反对

使用道具 举报

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

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-5-23 12:11 , Processed in 0.025847 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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