
1、C宏定义字符串拼接下图宏定义方法可将两个字符串进行拼接中间以空格隔开2、栈例1以下为Stack.h内容#ifndef_STACK_H_#define_STACK_H_/* 基本类型 */typedefsignedcharint8;typedefsignedshortint16;typedefsignedlongint32;typedefunsignedcharuint8;typedefunsignedshortuint16;typedefunsignedlonguint32;/* 栈的类型 */typedefint8 Stack_Type;typedefstructStack_Struct{Stack_Type*Stack_Base;/* 栈低 */Stack_Type*Stack_Top;/* 栈顶 */intStack_Max;/* 栈的最大值 */}Stack_Struct;/* 基本状态 */typedefenum{Stack_OK0,Stack_Error,Stack_Overlow,}Stack_Status_Type;#endif以下为Stack.c内容#includeStack.h#defineSTACK_MAX_SIZE100/* 栈最大空间 */Stack_Status_TypeStack_Init(Stack_Struct*Stack){Stack_Status_Type Stack_Status;Stack.Stack_Base(int8*)malloc(STACK_MAX_SIZE*sizeof(Stack_Type));if(!(Stack.Stack_Base)){Stack_StatusStack_Error;}else{Stack.Stack_TopStack.Stack_Base;Stack.Stack_MaxSTACK_MAX_SIZE;Stack_StatusStack_OK;}returnStack_Status;}Stack_Status_TypePush_Stack(Stack_Struct*Stack,Stack_Type*Stack_Value){Stack_Status_Type Stack_Status;if((Stack.Stack_Top-Stack.Stack_Base)Stack.Stack_Max){Stack_StatusStack_Overlow;}else{Stack.Stack_Top;*Stack.Stack_Top*Stack_Value;Stack_StatusStack_OK;}returnStack_Status;}Stack_Status_TypePop_Stack(Stack_Struct*Stack,Stack_Type*Stack_Value){Stack_Status_Type Stack_Status;if(*Stack.Stack_Top*Stack.Stack_Base){Stack_StatusStack_Error;}else{*Stack_Value*Stack.Stack_Top;Stack.Stack_Top--;Stack_StatusStack_OK;}returnStack_Status;}Stack_Status_TypeStack_Used_length(Stack_Struct*Stack,uint8*Length){Stack_Status_Type Stack_Status;*LengthStack.Stack_Top-Stack.Stack_Base;Stack_StatusStack_OK;returnStack_Status;}3、HEXView请在附件中获取4、Const and Volatileconst• 编译期限制const告诉编译器这个变量在源代码中不能被修改否则会报错。• 常量优化编译器通常会把 const 变量放在符号表中而不是分配内存从而在编译期直接替换成常量值。• 注意只在编译期有效运行时仍可能通过指针强制修改其值虽然这是不安全的做法volatile• 防止优化volatile告诉编译器这个变量的值可能被外部因素改变如硬件寄存器、其他线程因此每次访问都必须从内存中读取而不能缓存或优化。• 运行期保证在运行时编译器会生成指令确保每次读写都是真实的内存操作Static在全局使用时只能在本.c文件中使用不能被extern到外部使用在整个运行周期能值一直存在不会被释放掉