C³ÌÐò£º¶¨Òåºê´òӡijλÓò¹²ÓжàÉÙλ
#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 */
Ïà¹ØÎĵµ£º
ÊÔÌâ5£º±àдһ¸öº¯Êý£¬×÷ÓÃÊǰÑÒ»¸öchar×é³ÉµÄ×Ö·û´®Ñ»·ÓÒÒÆn¸ö¡£±ÈÈçÔÀ´ÊÇ“abcdefghi”Èç¹ûn=2£¬ÒÆÎ»ºóÓ¦¸ÃÊÇ“hiabcdefgh”
¡¡¡¡º¯ÊýÍ·ÊÇÕâÑùµÄ£º
//pStrÊÇÖ¸ÏòÒÔ'\0'½áβµÄ×Ö·û´®µÄÖ¸Õë
//stepsÊÇÒªÇóÒÆ¶¯µÄn
void LoopMove ( char * pStr, int steps )
{
¡¡//ÇëÌî³ä...
}
¡¡¡¡½ ......
ÓúêʵÏÖÒ»¸ö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 ......
googletest C/C++ ²âÊÔ¿ò¼Ü·Ç³£ºÃÓ㬽éÉܼ°ÏÂÔØÇë¿´ http://code.google.com/p/googletest/
//============================================================================
// ʹÓà googletest ²âÊÔ¿ò¼Ü
//============================================================================
// Returns n! ......
/*
˼·£ºµÝ¹éËã·¨
´Ó¿ªÊ¼ÍùºóµÝÔöµØÐ´Êý×Ö£¬µ±Ç°´ÓnowÖµ¿ªÊ¼£¬´æ´¢µÄλÖôÓcur¿ªÊ¼£¬
ÔòÏÔÈ»¼ÓÉÏ£¬now..n£¬¶¼ÊÇеÄ×éºÏÊý£¬¶ÔÓÚÿһ¸ö£¬{ Êä³öÖ®£¬È»ºóµÝ¹é£¬´¦Àí _c(n, cur+1, a, i+1) }
*/
/* Êä³ö1,2,3,..,nµÄ×éºÏÊý */
#include <stdio.h>
#include <assert.h>
#include <malloc.h>
void ......
/*
×¢Òâ²»¶ÏÓÒÒÆÅжÏ×îµÍλÊÇ1ÓжàÉÙ¸öµÄËã·¨ÊÇ´íÎóµÄ£¬
ÒòΪ¸ù¾ÝGNU C/C++µÄʵÏÖÀ´¿´£¬¸ºÊýÊÇ´ø·ûºÅÌî³ä½øÐÐÓÒÒÆµÄ£¬ËùÒÔÈç¹ûÊǸºÊý£¬¸ÃËã·¨»áËÀÑ»·¡£
±äͨ°ì·¨£ºJava¿ÉÒÔÓÃ>>>Âß¼ÓÒÒÆÎ»²Ù×÷·û£¬C/C++¿ÉÒÔÇ¿ÖÆ×ª»»³ÉÎÞ·ûºÅÕûÊýÔÙ´¦Àí
ÏÂÃæµÄ³ÌÐòÊÇÕý½â¡£ÆäÖÐnum &= (num - 1) »áÏû³ýnumµÄ×îСλÖõÄ"1" ......