全部博文(413)
分类: C/C++
2006-11-07 13:24:04
The C Preprocessor:
http://developer.apple.com/documentation/DeveloperTools/gcc-4.0.1/cpp/index.html#Top
1, 宏
__FILE__
__LINE__
__func__
__FUNCTION__ 同__func__
__PRETTY_FUNCTION__ 这个宏比__FUNCTION__功能更强, 若用g++编译C++程序,
__FUNCTION__只能输出类的成员名,不会输出类名; 而__PRETTY_FUNCTION__则会以
__DATE__
__TIME__
2, printf函数
%d %u int, unsigned int
%ld %lu long, unsigned long
%lld %llu long long, unsigned long long
3, 关于long long数据类型
#define NUM1 100ll
#define NUM2 100ull
#define NUM3 100llu
long long num1 = NUM;
unsigned long long num2 = NUM2;
unsigned long long num3 = NUM3;
4, 求x的2进制数中含1的个数。
int func(x)
{
int countx = 0;
while(x)
{
countx ++;
x = x&(x-1);
}
return countx;
}
5, ({statement1;...;statementn;})
执行{}内的statements,并返回statementn的结果.
eg:
int i = ({int j, k, l; j = 2; k = 3; l = j + k;});
执行后,i的值为5
7, gcc 常用选项
va_start(va, fmt);
while (*fmt)
{
switch(*fmt++)
{
case 's':
s = va_arg(va, char *);
printf("string %s\n", s);
break;
case 'd':
d = va_arg(va, int);
printf("int %d\n", d);
break;
case 'c':
c = va_arg(va, char);
printf("char %c\n", c);
break;
}