Here, we will learn about c programming macros, how to define and un define a macro, how and when macro expands?What is Macro?Macros are the names of text/ literal values/ string (constant values) or code fragm
In this example, we have todefine two macros YES with the constant value 1 and NO with the constant value 0by using#definepreprocessor directive in C programming language. Macros definitions #define YES 1 #define NO 0 Example #include<stdio.h>#defineYES 1#defineNO 0//function to check ...
[root@rockylinux tmp]# cat macro_define.c /** * 宏命定义的注意事项: * 1、带有参数的宏,参数使用时需要写在"()"之中,这样在宏展开时不会改变设计时的运算级别,保证结果正确;* 举例:#define MAX_INT(x,y) (x)>(y)?(x):(y) * 2、多行合并为一行(代码换行):当“宏定义”内容超过一行时...
You could work around this by requiring the user of the macro not to put a semicolon at the end. However, this is highly unnatural and tends to mess with things like automatic code indenting. A better way to fix it is to wrap the function in ado ... while(0)construct. This construc...
C / ANSI-C Macro Preprocessor Macro Function Define Macro as simple function #include <stdio.h> #define SUM(i, j) ((i)+(j)) int main(void) { int sum; sum = SUM(10, 20); printf("%d", sum); return 0; } Related examples in the same category...
Use in main routine : void main() { Delay(); // Delay 3000 Machine Cycles } => For easier use, i should write a DelayMCs() Macro, eg : #define DelayMCs(Interval) //Code Here??? Then, use this Macro like this : void main() { DelayMCs(7000); } => That's my idea. ...
define call(x,y) x##y把x和y连接起来,相当于新变量xyxy+call(x,y) 就相当于xy+xy=20+20=40;参考资料:The preprocessor operator ## provides a way to concatenate actual arguments during macroexpansion. If a parameter in the replacement text is adjacent to a ##, the parameter ...
I use KeilC uVision4 for 89C51 MCU. I use "Inline ASM Code", like this : void main() { #pragma ASM MOV R7, #( 80000/40000 ) #pragma ENDASM } -
C // Macro to define cursor lines#defineCURSOR(top, bottom) (((top) << 8) | (bottom))// Macro to get a random integer with a specified range#definegetrandom(min, max) \ ((rand()%(int)(((max) + 1)-(min)))+ (min)) ...
A(x) T_##xdefine B(x) #@xdefine C(x) #x我们假设:x=1,则有:A(1)---〉T_1B(1)---〉'1'C(1)---〉"1"(这里参考了 hustli的文章)3.define的多行定义define可以替代多行的代码,例如MFC中的宏定义(非常的经典,虽然让人看了恶心)define MACRO(arg1, arg2) do {...