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

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


Ïà¹ØÎĵµ£º

C ³ÌÐòµÄÍⲿ±äÁ¿Ó뺯Êý

±¾ÎÄÌÖÂÛÁËC³ÌÐòµÄÍⲿ±äÁ¿ºÍº¯ÊýµÄһЩÐÔÖÊ£¬½áºÏʵ¼ÊµÄ±à³Ì£¬¸ø³öÁËʹÓÃÍⲿ±äÁ¿ºÍº¯ÊýµÄ·½·¨¡£
¹Ø¼ü×Ö£ºC³ÌÐò£¬Íⲿ±äÁ¿£¬º¯Êý
¡¡¡¡C³ÌÐòÓÉÒ»×é¶ÔÏó×é³É£¬ÕâЩ¶ÔÏó°üÀ¨³ÌÐòÖÐËùʹÓõıäÁ¿ºÍʵÏÖÌØ¶¨¹¦Äܵĺ¯Êý¡£±äÁ¿¿ÉÒÔ·ÖΪº¯ÊýÄÚ²¿¶¨Ò塢ʹÓõıäÁ¿ºÍº¯ÊýÍⲿ¶¨ÒåµÄ±äÁ¿£¬Í¨³£Çé¿öÏ£¬°Ñº¯ÊýÄÚ²¿¶¨Ò塢ʹÓõıäÁ¿³ÆÎ ......

linux³£ÓÃcº¯Êý ÎļþȨÏÞ¿ØÖÆÆª

access£¨ÅжÏÊÇ·ñ¾ßÓдæÈ¡ÎļþµÄȨÏÞ£©
¡¡¡¡Ïà¹Øº¯Êý  stat£¬open£¬chmod£¬chown£¬setuid£¬setgid
¡¡¡¡±íÍ·Îļþ  #include<unistd.h>
¡¡¡¡¶¨Ò庯Êý  int access(const char * pathname,int mode);
¡¡¡¡º¯Êý˵Ã÷  access()»á¼ì²éÊÇ·ñ¿ÉÒÔ¶Á/дijһÒÑ´æÔÚµÄÎļþ¡£²ÎÊýmodeÓм¸ÖÖÇé¿ö×éºÏ£¬R_OK ......

CµÄ18¸ö¾­µäÎÊÌâ¡£

1.ÕâÑùµÄ³õʼ»¯ÓÐʲôÎÊÌ⣿char *p = malloc(10); ±àÒëÆ÷Ìáʾ“·Ç·¨³õʼʽ” ÔÆÔÆ¡£
´ð:Õâ¸öÉùÃ÷ÊǾ²Ì¬»ò·Ç¾Ö
²¿±äÁ¿Â𣿺¯Êýµ÷ÓÃÖ»ÄܳöÏÖÔÚ×Ô¶¯±äÁ¿(¼´¾Ö²¿·Ç¾²Ì¬±äÁ¿) µÄ³õʼʽÖС£
ÒòΪ¾²Ì¬±äÁ¿µÄµØÖ·±ØÐëÔÚ±àÒëµÄ¹ý³ÌÖоÍÈ·¶¨ÏÂÀ´¶ømalloc()Éê
ÇëµÄÄÚ´æµØÖ·ÊÇÔÚÔËÐÐʱȷ¶¨µÄ¡£
2. *p++ ×ÔÔöp »¹ÊÇp ËùÖ ......

¹ØÓÚC/C++ÖÐÄÚ´æ¿Õ¼äµÄ»®·Ö

CAPTION: ¹ØÓÚC/C++ÖÐÄÚ´æ¿Õ¼äµÄ»®·Ö
AUTHOR: aIsland Õª×ÔÖйúITʵÑéÊÒ
DATE: 2010-05-30
E-MAIL: aIsland@live.cn
QQ: 418662213
P.S.
     1.Bolanlan|ËæÐÄhigh|aIsland Èý¸öÍøÃû¾ùΪ±¾ÈË
     2.ÉùÃ÷aIsland ËùÊÕ¼µÄËùÓÐÎÄÕÂÆäÖø×÷Ȩ¶¼ÊôÓÚÔ­´´×÷Õß
   ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ