如何得到这个c宏的工作? [英] How to get this c macro working?
本文介绍了如何得到这个c宏的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么使用的开和关宏造成问题。
我是新来使用C宏。
是宏观声明正确的或者是有一些其他的问题与code。
请帮忙 ??
#包括LT&;&stdio.h中GT;
#包括LT&;&stdint.h GT;的#define ONE 1; //或者1 [0 0 0 0 0 0 0 1]在LSB位置插入1
#定义TWO_FIVE_FOUR 254; //并通过254 [1 1 1 1 1 1 1 0]到LSB的位置插入0上的#define(X)(X | ONE)
#定义关闭(X)(X&安培; TWO_FIVE_FOUR)诠释的main()
{
uint8_t有一个= 53; 的printf(字节的\\ n值数:%d,一); 的printf(字节的B \\ n值数:%d,在(a)条); //错误 的printf(字节的c \\ n值数:%d,关闭(一)); //错误 的getchar(); 返回0;
}
解决方案
从宏定义中删除分号
的#define ONE 1 //或1 [0 0 0 0 0 0 0 1]在LSB位置插入1
的#define TWO_FIVE_FOUR 254 //和254 [1 1 1 1 1 1 1 0]到LSB的位置插入0
Why is the use of the on and off macro creating problems. I am new to using c macros. Is the macro declaration correct or is there some other problem with the code. Please help ??
#include<stdio.h>
#include<stdint.h>
#define ONE 1; // OR BY 1 [ 0 0 0 0 0 0 0 1 ] TO insert 1 at LSB position
#define TWO_FIVE_FOUR 254; // AND BY 254 [ 1 1 1 1 1 1 1 0 ] TO insert 0 at LSB position
#define on(x) (x|ONE)
#define off(x) (x & TWO_FIVE_FOUR)
int main()
{
uint8_t a=53;
printf("\nValue of byte a : %d",a );
printf("\nValue of byte b : %d",on(a)); //Error
printf("\nValue of byte c : %d",off(a)); //Error
getchar();
return 0;
}
解决方案
Remove the semicolons from the macro definitions
#define ONE 1 // OR BY 1 [ 0 0 0 0 0 0 0 1 ] TO insert 1 at LSB position
#define TWO_FIVE_FOUR 254 // AND BY 254 [ 1 1 1 1 1 1 1 0 ] TO insert 0 at LSB position
这篇关于如何得到这个c宏的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文