[תÔØ]C/C++ÓïÑÔÎóÇøÒ» —— void main( )
ÔÚÍøÉÏ¿´µ½ÁËÕâƪÎÄÕ£¬·Ç³£²»´í£¬»ñÒæ·Ëdz£¬ÓÚÊÇת¹ýÀ´£¬Ï£ÍûÄܶԴó¼ÒÓÐËùñÔÒæ¡£ÎÄÕÂÔ×÷Õߣºantigloss http://free3.e-168.cn/antigloss/
ºÜ¶àÈËÉõÖÁÊÐÃæÉϵÄһЩÊé¼®£¬¶¼Ê¹ÓÃÁËvoid main( ) £¬ÆäʵÕâÊÇ´íÎóµÄ¡£C/C++ ÖдÓÀ´Ã»Óж¨Òå¹ývoid main( ) ¡£C++ Ö®¸¸ Bjarne Stroustrup ÔÚËûµÄÖ÷Ò³É쵀 FAQ ÖÐÃ÷È·µØд×Å The definition void main( ) { /* ... */ } is not and never has been C++, nor has it even been C.£¨ void main( ) ´ÓÀ´¾Í²»´æÔÚÓÚ C++ »òÕß C £©¡£ÏÂÃæÎÒ·Ö±ð˵һÏ C ºÍ C++ ±ê×¼ÖÐ¶Ô main º¯ÊýµÄ¶¨Òå¡£
1. C
ÔÚ C89 ÖУ¬main( ) ÊÇÕýÈ·µÄ¡£Brian W. Kernighan ºÍ Dennis M. Ritchie µÄ¾µä¾ÞÖø The C programming Language£¨¡¶C ³ÌÐòÉè¼ÆÓïÑÔ¡·£©ÓõľÍÊÇ main( )¡£²»¹ýÔÚ×îÐ嵀 C99 ±ê×¼ÖУ¬Ö»ÓÐÒÔÏÂÁ½ÖÖ¶¨Ò巽ʽÊÇÕýÈ·µÄ£º
int main( void )
int main( int argc, char *argv[] )
£¨²Î¿¼×ÊÁÏ£ºISO/IEC 9899:1999 (E) Programming languages — C 5.1.2.2.1 Program startup£©
µ±È»£¬ÎÒÃÇÒ²¿ÉÒÔ×öÒ»µãССµÄ¸Ä¶¯¡£ÀýÈ磺char *argv[] ¿ÉÒÔд³É char **argv£»argv ºÍ argc ¿ÉÒԸijɱðµÄ±äÁ¿Ãû£¨Èç intval ºÍ charval£©£¬²»¹ýÒ»¶¨Òª·ûºÏ±äÁ¿µÄÃüÃû¹æÔò¡£
Èç¹ûÄã²»ÐèÒª´ÓÃüÁîÐÐÖлñÈ¡²ÎÊý£¬ÇëÓà int main( void ) £»·ñÔòÇëÓà int main( int argc, char *argv[] ) ¡£
main º¯ÊýµÄ·µ»ØÖµÀàÐͱØÐëÊÇ int £¬ÕâÑù·µ»ØÖµ²ÅÄÜ´«µÝ¸ø³ÌÐòµÄ¼¤»îÕߣ¨Èç²Ù×÷ϵͳ£©¡£
Èç¹û main º¯ÊýµÄ×îºóûÓÐд return Óï¾äµÄ»°£¬C99 ¹æ¶¨±àÒëÆ÷Òª×Ô¶¯ÔÚÉú³ÉµÄÄ¿±êÎļþÖУ¨Èç exe Îļþ£©¼ÓÈë return 0 £¬±íʾ³ÌÐòÕý³£Í˳ö¡£²»¹ý£¬ÎÒ»¹Êǽ¨ÒéÄã×îºÃÔÚ main º¯ÊýµÄ×îºó¼ÓÉÏ return Óï¾ä£¬ËäȻûÓÐÕâ¸ö±ØÒª£¬µ«ÕâÊÇÒ»¸öºÃµÄÏ°¹ß¡£×¢Ò⣬vc6 ²»»áÔÚÉú³ÉµÄÄ¿±êÎļþÖмÓÈë return 0 £¬´ó¸ÅÊÇÒòΪ vc6 ÊÇ 98 ÄêµÄ²úÆ·£¬ËùÒԲŲ»Ö§³ÖÕâ¸öÌØÐÔ¡£ÏÖÔÚÃ÷°×ÎÒΪʲô½¨ÒéÄã×îºÃ¼ÓÉÏ return Óï¾äÁË°É£¡²»¹ý£¬gcc3.2£¨Linux ϵ
Ïà¹ØÎĵµ£º
1.MFCÖеķ½·¨£º(C++) CFileStatus status;
CFile::GetStatus("D:\\test.txt",status);
long lSizeOfFile;
lSizeOfFile = status.m_size; lSizeOfFileµÄÖµ¾ÍÊÇD:\\test.txtÎļþµÄ´óС 2.±ê×¼C»ñµÃÎļþ´óСµÄ5ÖÖ·½·¨
(×¢Ò⣺"__FILE__"Ö¸µÄÊǵ±Ç°Îļþ£¬Äã¿ÉÒÔ¸ÄΪÓÐЧ·¾¶µÄÄ¿±êÎļþ£¬±ÈÈç"D:\\test.tx ......
ÓÃVIM±àдC/C++³ÌÐò£¨×ªÔØ£©
ÓÃVIM±àдC/C++³ÌÐò
ViÊÇUnixÏÂ×î³£ÓõÄÎı¾±à¼Æ÷¡£VIM£¨Vi IMproved£©ÔòÊÇËüµÄÔöÇ¿°æ¡£ÓÐÈ˳£³£ÄÃVIMºÍemacs±È½Ï£¬VIM¾¡¹Ü²»ÏóemacsÄÇÑùÓÐÄÇô¶àµÄ¹¦ÄÜ£¬µ«ÊDZÈemacs¸ü·½±ã¡¢ºÃÓá£ÓùýemacsµÄÈ˿϶¨»áΪemacsµÄһЩ¿ì½Ý¼ü¸Ðµ½·³ÄÕ£¬ÓÐʱºòÓÃÕæÏ£Íû×Ô¼ºÓаËÖ»ÊÖ¡£VIMµÄѧϰÇúÏßÒ²²»ÏóemacsÄ ......
1.ÒýÑÔ
¡¡¡¡C++ÓïÑԵĴ´½¨³õÖÔÊÇ¡°a better C¡±£¬µ«ÊÇÕâ²¢²»Òâζ×ÅC++ÖÐÀàËÆCÓïÑÔµÄÈ«¾Ö±äÁ¿ºÍº¯ÊýËù²ÉÓõıàÒëºÍÁ¬½Ó·½Ê½ÓëCÓïÑÔÍêÈ«Ïàͬ¡£×÷ΪһÖÖÓûÓëC¼æÈݵÄÓïÑÔ£¬C++±£ÁôÁËÒ»²¿·Ö¹ý³ÌʽÓïÑÔµÄÌص㣨±»ÊÀÈ˳ÆΪ¡°²»³¹µ×µØÃæÏò¶ÔÏó¡±£©£¬Òò¶øËü¿ÉÒÔ¶¨Òå²»ÊôÓÚÈκÎÀàµÄÈ«¾Ö±äÁ¿ºÍº¯Êý¡£µ«ÊÇ£¬C++±Ï¾¹ÊÇÒ»ÖÖÃæÏò¶ ......
ÏÈÓñ´¶ûµÄÒ»µÀ±ÊÊÔÌâ¼òÒªµÄ˵Ã÷һϰɣº
¡¾Ì⡿˵Ã÷ÒÔϳÌÐò¡£
#include
int main(void)
{
unsigned int a[3] = {0x01020304, 0x05060708, 0x090a0b0c};
unsigned int *p = (unsigned int *)((int)a +1);¢Ù
printf("%x\n", *p);
return 0;
}
¡¾ÌâÄ¿½âÎö¡¿
Õâ¶Î³ÌÐòµÄÊä³ö½á¹ûÓ¦ ......