C程序:定义宏打印某位域共有多少位
#include <stdio.h>
#define bits(p, d) { \
int _tmp=p->d, _bits=0; \
for (p->d=1; p->d; p->d<<=1) \
_bits++; \
p->d=_tmp; \
printf("%s->%s has %d bits", #p, #d, _bits); \
}
typedef struct _s{
int a:4;
} S;
int main()
{
S tmp, *s = &tmp;
bits(s,a);
}
/* 输出: s->a has 4 bits */
相关文档:
在C++中,关于CPP的头文件互相包含的问题很让人头疼,其实我们谁也不愿意弄的结构混乱,难以理解,但有时又是有必须的。
假定当前有两个头文件分别为 A.h 和 B.h,内容分别如下:
A.h内容为:
#ifndef  ......
C没有类
这让人很疲惫
对象的说法很时髦
不就是继承封装组合人人会
右走是C++,这个大众都熟悉它
左走就是objective-c,躲在僻静僻静的麦金塔
本是同根生的C
如何高举面向对象的大旗
求同存异标新立异且听一一细分清
对象的C
是不同的C
类的处理与众不同重点要区分
不重复是我的口头禅
任何时候我只说一次告诉 ......
#include <stdio.h>
#include <string.h> /* 程序多次调用biodkey(),应包含头文件bios.h */
#include <bios.h><br>/* 程序多次调用clrscr(),应包含头文件conio.h */
#include <conio.h>
#define MAX 100
#define PAGE 2
#define PRINT1 printf("------------------------------ ......
#include<stdio.h>
#include<math.h>
float x1,x2,disc,p,q;
int main()
{
void greater_than_zero(float,float);
void equal_to_zero(float,float);
void smaller_than_zero(float,float);
float a,b,c;
printf("\ninput a,b,c:");
scanf("%f,%f,%f",&a,&b,&c) ......
用宏实现一个swap功能
#include <stdio.h>
#include <stdlib.h>
#define SWAP( TYPE,ARG1,ARG2 ) \
void TYPE##Swap( TYPE *p, TYPE *q ) \
{ \
TYPE tmp = *p; \
*p = *q; \
*q = tmp; \
} \
TYPE##Swap(&ARG1,&ARG2 ......