ºìÁªLinuxÃÅ»§
Linux°ïÖú

LinuxϵĴúÂë´ã»ð¼¼Êõ

·¢²¼Ê±¼ä:2006-08-29 09:47:15À´Ô´:ºìÁª×÷Õß:xuanchengzi
¡¾IT168 ʵÓü¼ÇÉ¡¿ÎÒÃÇÖªµÀ£¬Ìú½³¾­³£°Ñ½ðÊô¹¤¼þ¼ÓÈȵ½Ò»¶¨Î¶È,È»ºóͻȻ½þÔÚË®»òÓÍÖÐʹÆäÀäÈ´,´Ó¶øÓÐЧÔö¼ÓÆäÓ²¶È¡£ÀàËƵģ¬Èí¼þ¿ª·¢ÈËÔ±Ò²¿ÉÒÔ²ÉȡijÖÖÊֶΣ¬´Ó¶øÏÔÖøÌá¸ßÈí¼þµÄ¿É¿¿ÐÔºÍÖÊÁ¿£¬ÎÒÃÇÐÎÏóµØ³Æ֮Ϊ´úÂë´ã»ð¼¼Êõ¡£

Ò»¡¢´úÂë´ã»ðµÄºÃ´¦

ÀíÏëÖУ¬Èí¼þ´ã»ð¼¼ÊõÊ×ÏÈÄܹ»Ô¤¼û´úÂëÖеÄÄÄЩµØ·½¿ÉÄܳö´í£¬È»ºó£¬ÒªÃ´´ø¸øÎÒÃÇÒ»ÖÖÄܹ»ÍêÈ«±ÜÃâ´íÎóµÄ·½Ê½±àд´úÂ룬ҪôÄܼ°Ê±Ê¶±ð³ö´íÎ󣬴Ӷø¸üÇáËɵظú×ÙÔ´´úÂë¡£ÓÈÆäÊǶÔÓÚCÓïÑÔ£¬ÒòΪËü²»ÊÇÒ»ÖÖ°²È«ÓïÑÔ£¬ËùÒÔ¸üÐèÒªÈí¼þ´ã»ð¼¼ÊõÀ´Ìá¸ßÈí¼þµÄ¿É¿¿ÐÔ¡£±¾ÎĽ«Ïêϸ½éÉÜLinuxϳ£ÓõĴúÂë´ã»ð·½·¨¡£

¶þ¡¢³£¼ûµÄÂë´ã»ð¼¼Êõ

´úÂë´ã»ð¼¼ÊõµÄÐÎʽ¸÷ÖÖ¸÷Ñù£¬ÎÒÃÇÕâÀïÒª½²µÄÊÇ°ïÖúÎÒÃǹ¹½¨¸ü¼ÓÇ¿½¡µÄ´úÂëµÄ¸÷ÖÖ¼¼Êõ¡£

1 .»º³åÇøÒç³öÎÊÌâ

»º³åÇøÊÇÒ»¸ö·Ç³£ÑÏÖصݲȫÎÊÌ⣬×îºÃµÄÇé¿öÏ¿ÉÄܵ¼ÖÂÈí¼þµÄÐÐΪ´íÂÒ£»ÑÏÖØʱ½«»áµ¼Ö±»»º³åÇøÀûÓóÌÐòËù¿ØÖƶøÖ´ÐÐÈκι¥»÷ÕßËùÏëÒªÖ´ÐеĴúÂë¡£Çë¿´ÏÂÃæµÄʾÀý´úÂ룺

[code]static char ourArray[100];
...
int i;
for ( i = 0 ; i < 100 ; i++ ) {
ourArray[i] = (char)(0x30+i);
}
ourArray[i] = 0; // Ô½½ç£¬Î£ÏÕ£¡[/code]

ÉÏÀýÖУ¬ÎÒÃǵĸ³Öµ²Ù×÷ÒѾ­Ô½¹ýÁËÊý×éµÄ±ß½ç¡£Ëü²¢Ã»ÓÐÔÚÎÒÃǵÄÊý×éÄÚÖ´ÐÐд²Ù×÷£¬ËüÊÇÔÚÊý×é±ß½çÖ®ºóµÄµÚÒ»¸ö×Ö½ÚÄÚ½øÐеÄд²Ù×÷¡£»»¾ä»°Ëµ£¬Êý×éÖ®ºóµÄµÚÒ»¸ö¶ÔÏó£¬ÎÞÂÛËüÊǽṹÌåÒ²ºÃ£¬»¹ÊÇÖ¸ÕëÒ²°Õ£¬ÏÖÔÚÒѾ­±»ÆÆ»µÁË¡£ÎªÁ˸ıäÕâÖÖÔã¸âµÄÇé¿ö£¬ÎÒÃÇÖ»ÐèÒªÑø³ÉÒ»ÖÖÁ¼ºÃµÄÏ°¹ß£¬ÄǾÍÊÇʹÓ÷ûºÅ³£Á¿À´Ö¸Ê¾Êý×éµÄ±ß½ç¡£¾ÍÏñÔÚÏÂÀýÖÐÒ»Ñù£¬ÎÒÃÇ´´½¨ÁËÒ»¸ö³£Á¿£¬À´¶¨ÒåÊý×éµÄ³¤¶È¡£ÕâÀïÓÐÒ»¸öС¼¼ÇÉ£¬ÄǾÍÊǼÙÉèÎÒÃÇÐèÒªµÄÊý×鳤¶ÈΪA£¬ÄÇôÔÚ¶¨ÒåÊý×鳤¶Èʱ£¬Êµ¼Ê³¤¶ÈÊÇA+1¡£Õâʱ£¬ÎÞÂÛÊý×鳤¶ÈÈçºÎ£¬¿ÉÒԿ϶¨µÄÊÇ£¬Êý×é[A]Ò»¶¨ÊǸÃÊý×éµÄ±ß½ç¡£»»¾ä»°Ëµ£¬ÎÒÃÇÁôÁËÒ»¸öÔªËصÄÓàÁ¿¡£ÈçÏÂËùʾ£º

[code]#define ARRAY_SIZE 100
static char ourArray[ARRAY_SIZE+1];
...
int i;
for (i = 0 ; i < ARRAY_SIZE ; i++ ) {
ourArray[i] = (char)(0x30+i);
}
ourArray[ARRAY_SIZE] = 0; //ΪÊý×éµÄ×îºóÒ»¸öÔªËظ³Öµ[/code]

¡¡¡¡2.¼ìÑé·µ»ØÖµ

ÏÖÔÚ£¬Èí¼þÖÐ×î³£¼ûµÄ´íÎóÊǺöÂÔÁË·µ»ØÖµµÄ¼ìÑé¡£Ðí¶à³ÌÐòÔ±ÔÚµ÷ÓÃϵͳº¯Êý»òÓû§×Ô¶¨ÒåµÄº¯Êýºó£¬Í¨³£»áäĿÀÖ¹ÛµØÈÏΪÕâЩº¯Êý»á³É¹¦µÄÖ´ÐС£µ±ÎÒÃÇ´òÔì¾­´ã»ð´¦ÀíµÄÈí¼þʱ£¬Ó¦µ±¼ì²é·µ»ØÖµ£¬²¢ÇÒÔÚ·µ»Øʧ°Üʱ£¬»¹Òª½øÐÐÍ×ÉÆ´¦Àí¡£±ÈÈ磺

[code] ret = printf( "Current value is %d\n", value );
if ( ret < 0 ) {
ret = printf( "An error occured emitting value.\n" );
}[/code]

3.¼ì²éÊäÈë/Êä³öÊý¾Ý

µ±ÎÒÃÇ¿ª·¢Ó¦ÓÃʱ£¬ÎÞÂÛÉæ¼°µ½Óû§µÄÊäÈ룬»òÕßÊÇͨ¹ýÍøÂç½øÐÐÊäÈ룬һ¶¨ÒªÑÏÃܹØÇÐÊäÈëÊý¾ÝµÄÇé¿ö£º±ÈÈç¶ÔÓÚ¸ø¶¨µÄ²Ù×÷Êý¾ÝÊÇ·ñ³ä·Ö£¬»òÕßÊÕµ½µÄÊý¾ÝÊÇ·ñ³¬¹ýÁËÔ¤ÁôµÄ»º³åÇø¿Õ¼ä¡£

4.Ϊ·ÖÖ§Óï¾äÌṩ±¸Ñ¡·½°¸

¶ÔÓÚswitchÓï¾äÀ´Ëµ£¬³£³£»áÒÅ©default²¿·Ö£¬Õâ»áµ¼ÖÂÎÞ·¨Ô¤Áϵĺó¹û¡£¾ÙÀýÀ´Ëµ£º

[code]switch( mode ) {
case OPERATIONAL_MODE:
/* Çл»µ½ÔËÐÐģʽ½øÐд¦Àí */
break;
case BUILT_IN_TEST_MODE:
/* Çл»µ½²âÊÔģʽ½øÐд¦Àí*/
break;
}[/code]

¼ÙÉèÏÖÔÚÎÒÃÇÓÖÌí¼ÓÁËÒ»ÖÖģʽ£¬µ«ÊÇÉÏÃæµÄ´úÂë¶ÎûÓм°Ê±µÃµ½¸üУ¬ÕâʱÈç¹ûÖ´ÐÐÁËÕâ¶Î´úÂ룬ִÐнá¹û½«ÎÞ·¨Ô¤ÁÏ¡£Èç¹û°üÀ¨default²¿·Ö£¬ÖÁÉÙÒ²ÄÜÀûÓøò¿·ÖÔÚ³öÏÖÎÊÌâʱ֪ͨµ÷ÓÃÕߣ¬¼´Ê¹ÔÚ´Ë·ÅÒ»¸öassert£¬Ò²ÄÜÔÚµ÷ÊÔʱ²¶»ñµ±Ê±µÄ×´¿ö¡£ÈçÏÂÀýËùʾ£º

[code]switch( mode ) {
case OPERATIONAL_MODE:
/*Çл»µ½ÔËÐÐģʽ½øÐд¦Àí */
break;
case BUILT_IN_TEST_MODE:
/* Çл»µ½²âÊÔģʽ½øÐд¦Àí */
break;
default:
assert(0);
break;
}[/code]

ÉÏÊöÎÊÌâ³ýÁË´æÔÚÓÚswitchÓï¾äÍ⣬»¹´æÔÚÓÚif/then/else·ÖÖ§Óï¾äÖС£ÏÂÃæ·Ö±ð¾ÙÀý˵Ã÷£º

[code]float coefficient = 0.0;
if (state == FIRST_STAGE) coefficient = 0.75;
else if (state == SECOND_STAGE) coefficient = 1.25;[/code]

×÷ÕßµÄÒâͼºÜÃ÷ÏÔ£¬ËüÊÇÏ£Íû¸ù¾Ý±äÁ¿stateµÄÖµµÄ²»Í¬£¬Ò²ÈñäÁ¿coefficientÈ¡²»Í¬µÄÖµ¡£µ«ÊÇÈç¹û±äÁ¿stateµÄÖµ±»ÆÆ»µ£¨±ÈÈçÓöµ½ÉÏÃæÌáµ½µÄ»º³åÇøÒç³öµÄÆÆ»µ£©£¬»òÕßʹËüÈ¡ÁËÒ»¸öÔ¤ÆÚÖ®ÍâµÄÖµ£¬ÄÇô±äÁ¿coefficientµÄÖµ¾Í»áÒ»Ö±ÊÇ0.0¡£Èç¹ûÕâÊÇÓÃÀ´¼ÆË㸶·ÑµÄ»°£¬ºó¹ûµÄÑÏÖØ¿ÉÏë¶øÖª¡£Òò´Ë£¬else·ÖÖ§Óï¾äÖÁÉÙÓ¦¸Ã°üº¬Ò»¸ö·ÖÖ§ÓÃÀ´²¶»ñ´íÎó£¬ÀýÈ磺

[code]float coefficient = 0.0;
if (state == FIRST_STAGE) coefficient = 0.75;
else if (state == SECOND_STAGE) coefficient = 1.25;
else coefficient = SAFE_ COEFFICIENT;[/code]

¾¡¹ÜÐí¶àÇé¿öÏÂβËæµÄelse·ÖÖ§²»ÊDZØÐëµÄ£¬µ«ÕâÑù×öÎÞÒÉΪÎÒÃǵĴúÂë¼ÓÁËÒ»°Ñ±£»¤É¡£¬ÒÔÃâÖý³É´ó´í¡£

¡¡¡¡4.×Ô±êʶ½á¹¹Ìå

ÔÚÇ¿ÀàÐÍÓïÑÔÖУ¬Èç¹ûʹÓ÷Ƿ¨µÄÊý¾ÝÀàÐͽ«»áµ¼ÖÂÔËÐÐʱ´íÎó¡£µ«¶ÔÓÚÈõÀàÐÍÓïÑÔ£¬±ÈÈçCÓïÑÔ£¬ÔÚÖ¸ÕëµÄ´«µÝºÍÀàÐÍת»»¹ý³ÌÖУ¬ºÜÈÝÒ×°ÑÀàÐÍ»ìÏý¡£Îª´Ë£¬ÎÒÃÇÒýÈëÀàËÆÓÚÇ¿ÀàÐÍÓïÑÔÖеÄÔËÐÐʱÀàÐͼìÑé˼Ïë¡£

ÏÖÔÚÎÒÃÇͨ¹ýʵÀýÀ´½²½â×Ô±êʶ½á¹¹Ì壬¾ßÌå´úÂëÈçÏÂËùʾ£º

[code]#include
#include
#include

#define TARGET_MARKER_SIG 0xFAF32000

typedef struct {

unsigned int signature;
unsigned int targetType;
double x, y, z;

} targetMarker_t;


#define INIT_TARGET_MARKER(ptr) \
((( targetMarker_t *)ptr)->signature = TARGET_MARKER_SIG)
#define CHECK_TARGET_MARKER(ptr) \
assert(((targetMarker_t *)ptr)->signature == \
TARGET_MARKER_SIG)


void displayTarget( targetMarker_t *target )
{

/* Ô¤Ïȼì²é target½á¹¹Ìå */
CHECK_TARGET_MARKER(target);

printf( "Target type is %d\n", target->targetType );

return;
}


int main()
{
void *object1, *object2;

/* н¨Á½¸ö¶ÔÏó */
object1 = (void *)malloc( sizeof(targetMarker_t) );
assert(object1);
object2 = (void *)malloc( sizeof(targetMarker_t) );
assert(object2);
/*°´ÕÕtarget marker½á¹¹Ìå³õʼ»¯object1 */
INIT_TARGET_MARKER(object1);

/* ³¢ÊÔÏÔʾobject1 */
displayTarget( (targetMarker_t *)object1 );

/* ³¢ÊÔÏÔʾobject2 */
displayTarget( (targetMarker_t *)object2 );

return 0;
}[/code]

ÔÚ´úÂëµÄµÚ6-12ÐУ¬¶¨ÒåÁËÎÒÃǵÄÄ¿±ê½á¹¹Ì壬ÆäÖÐÓÐÒ»¸öרÃŵÄÍ·²¿£¬ÃûΪsignature£¨Ê¶±ð±êÖ¾£©£¬¼´¸Ã½á¹¹ÀàÐ͵ÄÔËÐÐʱÀàÐͱêʶ·û¡£²¢ÇÒÔÚµÚ4ÐÐΪ¸ÃÀàÐͶ¨ÒåÁËÒ»¸öʶ±ð±êÖ¾£¬×÷Ϊ¸Ã½á¹¹ÀàÐ͵ÄΨһÃèÊö·ûºÅ¡£´ËÍ⣬´úÂëÖл¹ÌṩÁËÁ½¸öºêINIT_TARGET_MARKERºÍCHECK_TARGET_MARKER£¬·Ö±ðÓÃÀ´³õʼ»¯ºÍ¼ìÑé¸Ã½á¹¹ÌåÖеÄʶ±ð±êÖ¾¡£

¼ÌÐøÍùºó¿´£¬Çë×¢Òâ´úÂëµÄ34-54ÐУ¬ÆäÖзÖÅäÁËÁ½¸öµÈͬ³¤¶È£¨targetMarker_t£©µÄÄÚ´æ¿Õ¼äÀ´¹©Á½¸ö¶ÔÏóʹÓã¬È»ºóÀûÓúêINIT_TARGET_MARKER½«ÆäÖÐÒ»¸ö³õʼ»¯£¬×îºó£¬·Ö±ðÀûÓÃdisplayTargetº¯ÊýÏÔʾ¡£

¶ÔÓÚµÚ22-31ÐеÄdisplayTargetº¯Êý£¬Ê×Ïȵ÷ÓÃCHECK_TARGET_MARKERÀ´¼ìÑéÊÕµ½µÄ¶ÔÏóµÄʶ±ð±êÖ¾£¬Èç¹û¸Ã±êÖ¾·Ç·¨£¬assert¾Í»á·¢»Ó×÷Óᣵ±È»£¬ÕâÀïÖ»ÊÇÒ»¸ö¸ÅÄîÐÔµÄÑÝʾ¡£

¡¡¡¡5.´íÎ󱨸æ

¶ÔÓÚ´íÎ󱨸æ¶øÑÔ£¬¸ù¾Ý¿ª·¢µÄÓ¦ÓÃÀàÐ͵IJ»Í¬£¬ÐèÒª²ÉÈ¡²»Í¬µÄ´¦Àí·½·¨¡£ÀýÈ磬Èç¹û¿ª·¢µÄÊÇÃüÁîÐй¤¾ßµÄ»°£¬³£Óõķ½·¨ÊÇͨ¹ý°Ñ´íÎóÏûÏ¢µÝ¸østderrÀ´¸æÖªÓÃÓû§³ö´íÇé¿ö¡£Èç¹û¿ª·¢µÄÊÇÖîÈçǶÈëʽLinuxÓ¦ÓÃÖ®ÀàµÄ¾ßÓÐI/OÄÜÁ¦µÄÓ¦ÓóÌÐòµÄ»°£¬´íÎ󱨸æµÄÐÎʽ¾Í¶àÁË£¬±ÈÈçרÃŵÄÈÕÖ¾»ò±ê׼ϵͳÈÕÖ¾£¨syslog£©¡£ÆäÖУ¬syslogº¯ÊýµÄÔ­ÐÍÈçÏÂËùʾ£º

[code] #include
void syslog( int priority, char *format, ... );[/code]

¶ÔÓÚsyslogº¯Êý£¬ÎÒÃÇÐèÒªÌṩÓÅÏȼ¶¡¢¸ñʽ»¯×Ö·û´®µÈ²ÎÊý¡£ËüµÄÓ÷¨ÀàËÆÓÚprintfº¯Êý¡£ÓÅÏȼ¶¿ÉÒÔ´ÓÕâÀïÑ¡ÔñÒ»¸ö£ºLOG_EMERG¡¢ LOG_ALERT¡¢LOG_CRIT¡¢LOG_ERR¡¢LOG_WARNING¡¢LOG_NOTICE¡¢LOG_INFO»òÕß LOG_DEBUG¡£ ÏÂÃæÒÔʵÀý˵Ã÷ÈçºÎʹÓÃsyslogº¯ÊýΪϵͳÈÕÖ¾Éú³ÉÒ»¸öÏûÏ¢£º

[code]#include

int main()
{

syslog( LOG_ERR, "Unable to load configuration!" );

return 0;
}[/code]

³ÌÐòÖ´Ðкó£¬Î»ÓÚ /var/log/_messagesµÄϵͳÈÕÖ¾¸üÐÂÈçÏ£º

[code] Aug 16 21:33:16 Ian test: Unable to load configuration![/code]

±¾ÀýÖУ¬testÊÇÉÏÃæÁгöµÄ³ÌÐòÃû£¬IanÊÇÖ÷»úÃû¡£ÏµÍ³ÈÕÖ¾µÄºÃ´¦ÊÇ¿ÉÒԼǼÐí¶àµÄ´íÎ󱨸档ƾ½èËü£¬¿ª·¢ÈËÔ±Äܹ»Á˽âÏûÏ¢ÔÚÄÄÀïÉú³ÉµÄ¡¢ÄÄÒ»¸öÄܹ»°ïÖúÀí½âÎÊÌâµÈµÈ¡£¶ÔÓÚϵͳӦÓúÍÊØ»¤½ø³ÌÀ´Ëµ£¬syslogµÄ¸ñÍâÓÐÓá£

³ý´ËÖ®Í⣬´íÎ󱨸滹ÓÐÒ»¸ö×¢ÒâÊÂÏÄǾÍÊDZ¨¸æµÄ´íÎóÒ»¶¨Òª¾ßÌ塣ΪÁËÄܹ»ÈÃÓû§Ç¡µ±µÄ´¦Àí·¢ÉúµÄ´íÎ󣬴íÎóÏûÏ¢Ò»¶¨ÒªÎ¨Ò»µÄ±êʶ³ö´íÎóÀ´¡£´íÎóÏûÏ¢±¾Éí²»ÄÜÄ£ÀâÁ½¿É£¬»òÕß¾ßÓÐÆçÒåÐÔ¡£

¡¡¡¡6.½µµÍ´úÂëµÄ¸´ÔÓÐÔ

½µµÍ¸´ÔÓÐԾ͵ÈÓÚ½µµÍ³ö´íµÄ»úÂÊ£¬ÒòΪ´úÂëÔ½¸´ÔÓ£¬°üº¬bugµÄ¿ÉÄÜÐÔÔ½´ó£¬²¢ÇÒÕÒµ½bugµÄÄѶÈÒ²Ô½´ó¡£Îª´Ë£¬ÎÒÃÇ¿ÉÒÔ½«Ò»¸ö¸´ÔӵĴúÂë¶Î£¬·Ö½â³É¶à¸ö¸üÈÝÒ×Àí½âµÄ¼¸¶Î´úÂë¡£ÕâÑùÒ»À´£¬Ëæ×Å´úÂëµÄ¿Éά»¤ÐÔµÄÌá¸ß£¬Èí¼þÖÊÁ¿×ÔÈ»ÓкܴóÌáÉý¡£

7.×Ô±£»¤ÐÔº¯Êý

ʹÓÃ×Ô±£»¤ÐÔº¯ÊýÊÇÒ»ÖÖÓÐЧµÄµ÷ÊÔ»úÖÆ£¬ËüÄܱ£Ö¤Èí¼þµÄÕýÈ·ÐÔ¡£ÕâÀïµÄ×Ô±£»¤Òâζ×Å£¬µ±Äãдһ¸öº¯ÊýµÄʱºò£¬±ØÐèÉóºË¸Ãº¯ÊýµÄÊäÈ룻²¢ÇÒÔÚÊäÈëÊý¾Ý´¦Àí³Éºó£¬»¹ÒªÉóºËÊý¾ÝµÄÊä³ö£¬´Ó¶øÈ·±£Ã»Óгö´í¡£ÏÂÃæÎÒÃÇÓÃÒ»¸öʵÀýº¯Êý¼ÓÒÔ˵Ã÷£º

[code]STATUS_T checkRegisterStatus( REGISTER_T register, MODE_T *mode )
{
REGISTER_STS_T retStatus;

/* ÑéÖ¤ÊäÈë */
assert( validRegister( register ) );
assert( validMode( mode ) );


/*--------------------*/
/*ÕâÀïÊ¡ÂÔcheckRegisterStatus µÄÄÚ²¿´¦Àí²¿·Ö */
/*--------------------*/


/* ¿ÉÄܸıäÁËģʽ£¬¼ìÑéÖ® */
assert( validMode( mode ) );

return retStatus;
}[/code]

×¢Ò⣬Èç¹û±í´ïÊǽá¹ûΪ·Ç£¨¼´0£©£¬assertº¯Êý¾Í»áÍ£Ö¹Ó¦Ó㬲¢ÔÚ±ê×¼Êä³öÉ豸ÉÏÉú³ÉÒ»¸ö´íÎóÏûÏ¢¡£¿ÉÒÔͨ¹ý¶¨Òå·ûºÅNDEBUGµÄ·½·¨À´Í£ÓÃassert¡£

´ÓÉÏÀýÖÐÎÒÃÇ¿´µ½£¬º¯ÊýÊ×ÏÈͨ¹ýÑéÖ¤ÊäÈëÀ´È·±£µÃµ½µÄÊý¾ÝÊÇÕýÈ·µÄ£¬È»ºóͨ¹ýÑéÖ¤Êä³öÀ´±£Ö¤Ëü¸ø³öµÄÊý¾ÝÒ²ÊÇÕýÈ·µÄ¡£¸ù¾Ý¾ßÌåÇé¿ö£¬ÎÒÃÇ¿ÉÄÜÊÕµ½´íÎóÏûÏ¢£¬¼´Ê¹ÕâÑùÎÒÃÇÒ²ÄÜÇá¶øÒ׾ٵط¢ÏÖ´íÎóÖ®ËùÔÚ¡£ÁíÍ⣬assertµÄ×÷Óò»½öÏÞÓÚÈ·±£º¯ÊýµÄÊäÈëÊä³öµÄÕýÈ·ÐÔ£¬»¹ÄÜÓÃÀ´È·±£ÄÚ²¿µÄÒ»ÖÂÐÔ¡£ËùÓÐÓ¦¸ÃÔÚµ÷ÊÔÆڼ䷢ÏÖµÄÑÏÖØ´íÎ󣬶¼¿ÉÒÔÀûÓÃassertÀ´ÇáËÉ´¦Àí¡£

8.ÓÅ»¯µ÷ÊÔÊä³ö

Ì«¶àµÄÊä³öÄܹ»ÑڸǴíÎ󣬵«Êä³ö¹ýÉÙÒ²»á©µô´íÎó£¬Òò´ËÎÒÃÇÐèҪѰÕÒÒ»¸öƽºâµã£¬Ê¹µÃÌṩµÄµ÷ÊÔÊä³öºÍ´íÎóÏûÏ¢¹»Ó㬵«ÓÖ²»»á¹ýÁ¿£¬ÕâÐèÒªÔÚʵ¼ùÖоßÌå°ÑÎÕ¡£

¡¡¡¡9.ÄÚ´æµ÷ÊÔ¼¼Êõ

ÔÚLinuxÖУ¬ÓÐÐí¶à³ÌÐò¿â¶¼¿ÉÒÔÓÃÀ´µ÷ÊÔ¶¯Ì¬ÄÚ´æ¹ÜÀí¡£×î³£¼ûµÄ Electric FenceÊÇÒ»¸ö¹¦ÄÜÇ¿´ó²¢ÇÒÄܼ°Ê±·¢ÏÖÄÚ´æ´íÎóµÄ¿â£¬Ëü²»½ö¿ÉÒÔÀûÓõͲ㴦ÀíÆ÷µÄÄÚ´æ¹ÜÀíµ¥ÔªMMUµÄ¶Î¹ÊÕÏÀ´²¶»ñÄÚ´æ´íÎ󣬶øÇÒ»¹ÄÜÕì²ìÊý×éÔ½½çÎÊÌâ¡£

10.±àÒëÆ÷µÄÖ§³Ö

ʵ¼ÊÉÏ£¬±àÒëÆ÷±¾Éí¾ÍÊÇÒ»¸öʶ±ð´úÂëÎÊÌâµÄÎÞ¼ÛÖ®±¦£¬µ±¹¹½¨³ÌÐòʱ£¬Ò»¶¨ÒªÊ¹ÓÃ-WallÏîÀ´ÆôÓñ¨¾¯¹¦ÄÜ¡£

´ËÍ⣬»¹¿ÉÒÔÀûÓÃ-Werror°Ñ¾¯¸æ×÷Ϊ´íÎó¶Ô´ý£¬´Ó¶øÍ£Ö¹¶ÔÔ´Îļþ½øÐнøÒ»²½µÄ±àÒ룬ÕâÑ¡Ïî¶ÔÓÚ´óÐÍÓ¦ÓóÌÐò¸ñÍâÓÐÓᣵ±ÎÒÃǹ¹½¨Óжà¸öÔ´Îļþ×é³ÉµÄÓ¦ÓóÌÐòʱ£¬ÎÒÃÇ¿ÉÒÔ½«Á½¸öÑ¡Ïî×éºÏʹÓá£ÈçÏÂÀýËùʾ£º

[code] gcc -Wall -Werror test.c -o test[/code]

Èç¹ûÎÒÃÇÏëÈÃÔ´´úÂëÄܹ»¼æÈÝANSI£¬ÎÒÃÇ»¹ÄÜÀûÓñàÒëÆ÷À´½øÐмì²é£¬Ó÷¨ÈçÏÂËùʾ£º

[code] gcc -ansi -pedantic test.c -o test[/code]

È·ÈϱäÁ¿ÒѾ­³õʼ»¯ÊǷdz£ÓÐÓõģ¬³ýÁËʹÓñ¨¾¯Ñ¡ÏîÍ⣬»¹ÐèҪʹÓÃÓÅ»¯Ñ¡ÏÒòΪֻÓо­¹ýÓÅ»¯µÄ´úÂë²ÅÄÜʹÓÃÊý¾ÝÁ÷ÐÅÏ¢£º

[code] gcc -Wall -O -Wuninitialized test.c -o test[/code]

ÒªÏëÁ˽â¸ü¶à£¬¿ÉÒԲο¼gccµÄmainÒ³¡£

Èý¡¢ С½á

±¾ÎÄÏêϸ½éÉÜÁË´úÂë´ã»ð¼¼ÊõµÄ¸ÅÄîÒÔ¼°Linuxϳ£Óõļ¸ÖÖ´úÂë´ã»ð·½·¨¡£ÔÚÏÂһƪÎÄÕÂÖУ¬ÎÒÃǽ«¼ÌÐø½éÉÜÓÃÀ´Ìá¸ßLinuxÓ¦ÓóÌÐò°²È«ÐԺͿɿ¿ÐԵĿªÔ´¹¤¾ßºÍ´úÂë×·×Ù¼¼Êõ¡£
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ