20150127 【 ARM 】 C语言+位域联合体

来源:互联网 发布:数据科学与r语言 编辑:程序博客网 时间:2024/05/17 09:31
结构体位域
struct Fpga
{
unsigned int a:1;
unsigned int b:1;
unsigned int c:1;
};
联合体:多个成员共用一块存储空间(占最大数据类型空间)
同一时刻只能用一个成员
union FPH
{
unsigned int p;
unsigned char ch;
};

union FPH mfph;
mfph.p = 10;
mfph.ch = 20;

位域与联合体
union FPA
{
struct 
{
unsigned int gpa0:2;
unsigned int gpa1:2;
unsigned int gpa2:2;
}gpac;
unsigned int gpa;
}
枚举:作用增强程序可读性


enum date{sun, mon, tue, wed, tur, fri, sat};

switch(day)
{
case sun:printf("星期天\n");break;
case mon:printf("星期一\n");break;
}



头文件中
#ifndef STD_H
#define STD_H
头文件内容---函数声明,变量声明,结构体声明
#endif//STD_H
常量,函数
#define PRINTF(X) printf("%s-%d-%s",__FILE__, __LINE__, X);
编译调试
#define DEBUG
#ifdef DEBUG
PRINTF(“error”);
#endif
跨平台
#ifdef WIN32
-----
#endif
#ifdef IOS
-----
#endif
#ifdef LINUX
-----
#endif
0 0
原创粉丝点击