Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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 */


Ïà¹ØÎĵµ£º

C/C++ ³ÌÐòÉè¼ÆÔ±Ó¦Æ¸³£¼ûÃæÊÔÊÔÌâÉîÈëÆÊÎöÖ®Èý


ÊÔÌâ5£º±àдһ¸öº¯Êý£¬×÷ÓÃÊǰÑÒ»¸öchar×é³ÉµÄ×Ö·û´®Ñ­»·ÓÒÒÆn¸ö¡£±ÈÈçÔ­À´ÊÇ“abcdefghi”Èç¹ûn=2£¬ÒÆÎ»ºóÓ¦¸ÃÊÇ“hiabcdefgh” 
¡¡¡¡º¯ÊýÍ·ÊÇÕâÑùµÄ£º
//pStrÊÇÖ¸ÏòÒÔ'\0'½áβµÄ×Ö·û´®µÄÖ¸Õë
//stepsÊÇÒªÇóÒÆ¶¯µÄn
void LoopMove ( char * pStr, int steps )
{
¡¡//ÇëÌî³ä...
}
¡¡¡¡½ ......

¶Ô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 ......

C³ÌÐò£ºÊ¹Óà googletest ²âÊÔ¿ò¼Ü

googletest C/C++ ²âÊÔ¿ò¼Ü·Ç³£ºÃÓ㬽éÉܼ°ÏÂÔØÇë¿´  http://code.google.com/p/googletest/
//============================================================================
// ʹÓà googletest ²âÊÔ¿ò¼Ü
//============================================================================

// Returns n! ......

C³ÌÐò£ºÊä³ö1,2,3,..,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 ......

C³ÌÐò£ºÈ·¶¨Ò»¸öÕûÊýµÄ¼ÆËã»úÄÚ²¿±íʾÖÐÓм¸¸ö"1"

/*
×¢Òâ²»¶ÏÓÒÒÆÅжÏ×îµÍλÊÇ1ÓжàÉÙ¸öµÄËã·¨ÊÇ´íÎóµÄ£¬
ÒòΪ¸ù¾ÝGNU C/C++µÄʵÏÖÀ´¿´£¬¸ºÊýÊÇ´ø·ûºÅÌî³ä½øÐÐÓÒÒÆµÄ£¬ËùÒÔÈç¹ûÊǸºÊý£¬¸ÃËã·¨»áËÀÑ­»·¡£
±äͨ°ì·¨£ºJava¿ÉÒÔÓÃ>>>Âß¼­ÓÒÒÆÎ»²Ù×÷·û£¬C/C++¿ÉÒÔÇ¿ÖÆ×ª»»³ÉÎÞ·ûºÅÕûÊýÔÙ´¦Àí
ÏÂÃæµÄ³ÌÐòÊÇÕý½â¡£ÆäÖÐnum &= (num - 1) »áÏû³ýnumµÄ×îСλÖõÄ"1" ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ