当前位置:网站首页>Macro definition usage and typedef and Const

Macro definition usage and typedef and Const

2022-06-22 11:56:00 Carefree young heart

typedef Can be used to define some of their own classes
const Definition fixed value cannot be modified

typedef int zhengxing;

zhengxing u = 10;
printf("%i \r\n", u);//10

const int i = 10;
i = 5;// Report errors 

first #if #endif If if If the latter condition is true, compile the code between them Otherwise, do not compile

#if 0
	char* ptr_size;//32 It's a plane : 4 byte  64 It's a plane : 8 byte  
	printf("%d \n",sizeof(ptr_size));
#endif // 0

the second :#define

#define num(a,b) a+b

int a = num(1, 3);
printf("%i", a);

Third use #define Define a function or class

// This ##  Is the function of the connection string 
// This can be used to FunName This parameter is linked to other content 
#define num1(FunName,a,b) \ int FunName##_Hello(int a,int b) \ {
      \ return a+b;\ }

num1(III, x, y);

int main()
{
    
 int e=III_Hello(1, 2);
 printf("%i \r\n", e);
}
// Macro defines a class 
#define num2(FunName,astring) \ class CCC_##FunName \ {
       \ public: \ CCC_##FunName() \ :a(#astring) \ {
      } \ char a; \ };
原网站

版权声明
本文为[Carefree young heart]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206221128283702.html