c ºê¶¨Òå
¹ØÓÚ#ºÍ##ÔÚCÓïÑԵĺêÖУ¬#µÄ¹¦ÄÜÊǽ«ÆäºóÃæµÄºê²ÎÊý½øÐÐ×Ö·û´®»¯²Ù×÷£¨Stringfication£©£¬¼òµ¥Ëµ¾ÍÊÇÔÚ¶ÔËüËùÒýÓõĺê±äÁ¿Í¨¹ýÌæ»»ºóÔÚÆä×óÓÒ¸÷¼ÓÉÏÒ»¸öË«ÒýºÅ¡£±ÈÈçÏÂÃæ´úÂëÖеĺ꣺
#define WARN_IF(EXP) \
do{ if (EXP) \
fprintf(stderr, "Warning: " #EXP "\n"); } \
while(0)
ÄÇôʵ¼ÊʹÓÃÖлá³öÏÖÏÂÃæËùʾµÄÌæ»»¹ý³Ì£º
WARN_IF (divider == 0);
±»Ì滻Ϊ
do {
if (divider == 0)
fprintf(stderr, "Warning" "divider == 0" "\n");
} while(0);
ÕâÑùÿ´Îdivider£¨³ýÊý£©Îª0µÄʱºò±ã»áÔÚ±ê×¼´íÎóÁ÷ÉÏÊä³öÒ»¸öÌáʾÐÅÏ¢¡£
¶ø##±»³ÆΪÁ¬½Ó·û£¨concatenator£©£¬ÓÃÀ´½«Á½¸öTokenÁ¬½ÓΪһ¸öToken¡£×¢ÒâÕâÀïÁ¬½ÓµÄ¶ÔÏóÊÇToken¾ÍÐУ¬¶ø²»Ò»¶¨ÊǺêµÄ±äÁ¿¡£±ÈÈçÄãÒª×öÒ»¸ö²Ëµ¥ÏîÃüÁîÃûºÍº¯ÊýÖ¸Õë×é³ÉµÄ½á¹¹ÌåµÄÊý×飬²¢ÇÒÏ£ÍûÔÚº¯ÊýÃûºÍ²Ëµ¥ÏîÃüÁîÃûÖ®¼äÓÐÖ±¹ÛµÄ¡¢Ãû×ÖÉϵĹØϵ¡£ÄÇôÏÂÃæµÄ´úÂë¾Í·Ç³£ÊµÓãº
struct command
{
char * name;
void (*function) (void);
};
#define COMMAND(NAME) { NAME, NAME ## _command }
// È»ºóÄã¾ÍÓÃһЩԤÏȶ¨ÒåºÃµÄÃüÁîÀ´·½±ãµÄ³õʼ»¯Ò»¸öcommand½á¹¹µÄÊý×éÁË£º
struct command commands[] = {
COMMAND(quit),
COMMAND(help),
...
}
COMMANDºêÔÚÕâÀï³äµ±Ò»¸ö´úÂëÉú³ÉÆ÷µÄ×÷Óã¬ÕâÑù¿ÉÒÔÔÚÒ»¶¨³Ì¶ÈÉϼõÉÙ´úÂëÃܶȣ¬¼ä½ÓµØÒ²¿ÉÒÔ¼õÉÙ²»ÁôÐÄËùÔì³ÉµÄ´íÎó¡£ÎÒÃÇ»¹¿ÉÒÔn¸ö##·ûºÅÁ¬½Ó n+1¸öToken£¬Õâ¸öÌØÐÔÒ²ÊÇ#·ûºÅËù²»¾ß±¸µÄ¡£±ÈÈ磺
#define LINK_MULTIPLE(a,b,c,d) a##_##b##_##c##_##d
typedef struct _record_type LINK_MULTIPLE(name,company,position,salary);
// ÕâÀïÕâ¸öÓï¾ä½«Õ¹¿ªÎª£º
// typedef struct _record_type name_company_position_salary;
¹ØÓÚ...µÄʹÓÃ
...ÔÚCºêÖгÆΪVariadic Macro£¬Ò²¾ÍÊDZä²Îºê¡£±ÈÈ磺
#define myprintf(templt,...) fprintf(stderr,templt,__VA_ARGS__)
// »òÕß
#define myprintf(templt,args...) fprintf(stderr,templt,args)
µÚÒ»¸öºêÖÐÓÉÓÚûÓжԱä²ÎÆðÃû£¬ÎÒÃÇÓÃĬÈϵĺê__VA_ARGS__À´Ìæ´úËü¡£µÚ¶þ¸öºêÖУ¬ÎÒÃÇÏÔʽµØÃüÃû±ä²ÎΪargs£¬ÄÇôÎÒÃÇÔں궨ÒåÖоͿÉÒÔÓÃargsÀ´´úÖ¸±ä²ÎÁË¡£Í¬CÓïÑÔµÄstd
Ïà¹ØÎĵµ£º
ÍøÉÏÒ»µÀ½ðɽµÄÃæÊÔÌ⣺
http://topic.csdn.net/u/20100524/14/0eff992a-2849-4db6-bdaa-d4a200e79b7c.html
Çë·Ö±ðÓÃC++µÄÃæÏò¶ÔÏóºÍ·ºÐÍ»úÖÆ£¬±àдʵÏÖTemplate MethodģʽµÄʾÀý´úÂ룬²¢±È½ÏÁ½ÖÖ·½Ê½¸÷×ÔµÄÓÅȱµã¡£
ÓÃÐ麯ÊýʵÏÖTemplate MethodµÄ·½Ê½¾Í²»¶à˵ÁË¡£Ó÷ºÐ͵ķ½Ê½ÊµÏÖ¶à̬ÔÚATLÀïÃæÓдóÁ¿µÄÓõ½£¡
·ºÐ͵ ......
ANSI C±ê×¼ÖÐÓм¸¸ö±ê×¼Ô¤¶¨Òåºê£º__FILE__ __DATE__ __TIME___ __LINE__ µÈ
__LINE__£ºÔÚÔ´´úÂëÖвåÈ뵱ǰԴ´úÂëÐкţ»
__FILE__£ºÔÚÔ´ÎļþÖвåÈ뵱ǰԴÎļþÃû£»
__DATE__£ºÔÚÔ´ÎļþÖвåÈ뵱ǰµÄ±àÒëÈÕÆÚ
__TIME__£ºÔÚÔ´ÎļþÖвåÈ뵱ǰ±àÒëʱ¼ä£»
......
/*
**ÅжÏC?ÐÐ??¾³µÄ³ÌÐò
*/
/*
**¾²?³õʼ»¯
*/
int static_variable=5;
void
f()
{
register int i1, i2, i3, i4, i5, i6, i7, i8, i9, i10;
register char *c1, *c2, *c3, *c4, *c5, *c6, *c7 , *c8, *c9, *c10;
extern int a_very_long_name_to_sec_how_long_they_can_be;
double ......
1.ÕâÑùµÄ³õʼ»¯ÓÐʲôÎÊÌ⣿char *p = malloc(10); ±àÒëÆ÷Ìáʾ“·Ç·¨³õʼʽ” ÔÆÔÆ¡£
´ð:Õâ¸öÉùÃ÷ÊǾ²Ì¬»ò·Ç¾Ö
²¿±äÁ¿Â𣿺¯Êýµ÷ÓÃÖ»ÄܳöÏÖÔÚ×Ô¶¯±äÁ¿(¼´¾Ö²¿·Ç¾²Ì¬±äÁ¿) µÄ³õʼʽÖС£
ÒòΪ¾²Ì¬±äÁ¿µÄµØÖ·±ØÐëÔÚ±àÒëµÄ¹ý³ÌÖоÍÈ·¶¨ÏÂÀ´¶ømalloc()Éê
ÇëµÄÄÚ´æµØÖ·ÊÇÔÚÔËÐÐʱȷ¶¨µÄ¡£
2. *p++ ×ÔÔöp »¹ÊÇp ËùÖ ......
ÒªÈà Eclipse ¿ÉÒÔ¿ª·¢ C/C++ ³Ìʽ£¬Òª¹ÒÉÏ CDT ²Å¿ÉÒÔ¡£
Ê×ÏÈÒªÏÂÔØCDT
CDTµÄ×îа汾ÊÇ 3.1.0£¬ËüÖ§³Öeclipse3.2.0£¬ÆäÏÂÔصØÖ·£ºhttp://download3.eclipse.org/tools/cdt/releases/callisto/dist/3.1.0/£¬»òÕßÊǵ½http://www.eclipse.org/cdt/downloads.phpÏÂÔØÆäËü° ......