\
/
©ì\tg
/
úL
/
ó
/
TCgîñ
/
õ
êÊ / Vb¾ê / ʶ |
| |
|
7.1@ÃÙÌÖé¾ @»ÝÌ C ¾êÌKiÅÍA éÖ©ç¼ÌÖðÄÑo·AÆÉ»ÌÖÌvg^Cvðé¾µÈÄàgp·é±ÆªÅ«Üµ½Bá¦Î stdio.h ðÇÝܸÉAprintf ðgp·éÆ¢Á½±ÆÅ·Bµ©µA¡xÌ C ¾êÅÍ»Ìæ¤ÈêA»ÌÖÌÄÑoµÍKiã¢è`Ì®ìÆÈèÜ·B½¾ÀÛÉͽÌnÅÍxðoµÄRpC·éæ¤À³êé±Æŵå¤B±ÌÓÌ@\Í C++ ÉßÈÁĢܷËB 7.2@é¾ÌÃÙÌ^ @豫^¾êÅÍAêÊIÉÏâÖÈÇðé¾µÄgp·éKvª èÜ·Bà¿ëñ C ¾êàáOÅÍ èܹñBµ©µ C ¾êÅÍÁÉ^¼ðw蹸ÉÏÈÇðé¾·é±ÆªÅ«Üµ½B»ÌêA^ªÈ¢Ïªé¾³ê½Æ¢¤í¯ÅÍÈA©®IÉ int ^Ƶijêܵ½Báð°êÎAÌæ¤ÈvOÅ·B
±ÌêAÖ func Ìßè^Í int ^Ap1, p2, three Ì^Í int ^Å·B ±Ìæ¤ÈLqªÅ«éÆ¢¤±Æª C ¾êÌ«¿ðæ çíµÄ¢Ü·B µ©µÈªçAVµ¢ C ¾êÅÍA±Ìæ¤ÈÃÙÌ int ^ÌgpÍKiãÅ«È¢±ÆÉÈèܵ½Bµ½ªÁÄAíÉÌæ¤ÉKvª èÜ·B
7.3@Oè`¯Ê¼ __func__ @¨Ò½¹µÜµ½BÒ]Ì@\Ìêªüèܵ½B»êªOè`¯Ê¼ __func__ Å·B @³Ä³ÄA¡ÜÅF³ñÍvOðÇÌæ¤ÉfobOðµÄ«Üµ½©H½HfobKðgÁÄ¢½H»Ìæ¤ÈØÈÂ«É élÍA±Ì@\Ì èª½³ðÀ´·é±Æªïµ¢©àµêܹñB @vOÌfobOÉ ½ÁÄܸåȱÆÍA¢Á½¢vOÍÇ̪ðÁÄ¢éÌ©Æ¢¤±Æðmé±ÆÅ·Bá¦ÎAðªòðµ½Æ«zèµ½R[hÌûð¿áñÆÊÁ½Ì©ðméKvª èÜ·B»Ìæ¤ÈÆ«ÉÍ printf ðßñ¾èµÄA³µ¢ûüÉvOªÀsµÄ¢é©ð¸·éKvª èܵ½Bµ©µAprintf ðßñ¾ªª½ÈÁÄéÆA¾ñ¾ñÇ±Ì printf ÌoÍÅ éÌ©ªí©çÈÈéÆ¢Á½âèª èܵ½B @Oè`¯Ê¼Í±Ìæ¤ÈøÊðöµÜ·Bá¦ÎA¡ñ±ü³ê½Oè`¯Ê¼ÆÂÏ·}N@\ðgÝí¹éÆÌæ¤È±ÆªÅ«Ü·B
@¡xÌ C ¾êÅÍA±ÌáÌ (1) ŦµÄ¢éæ¤ÉAeÖÌüèûÅ __func__ Æ¢¤¯Ê¼ª ½©à©®IÉ龳꽩Ìæ¤ÉÈèÜ·Bµ½ªÁÄA±ÌÖÌXR[v __func__ ðQÆ·é±ÆªÅ«Ü·B__func__ Í»ÌÖÌÖ¼ªüèÜ·B±ÌêAÖ¼ª foo_bar ÈÌÅ __func__ Í "foo_bar" ð çí·±ÆÉÈèÜ·BáÌÅÍ i ª 3 ÅÍÈ¢ÆfobOR[hðÀsµÜ·B¡ i ª 5 Å éÆl¦éÆAutest.c 13 @foo_bar: i=5vÌæ¤È\¦ªÈ³êÜ·B @±Ìæ¤ÉA¡ñÌ C ¾êÌ@\ðg¤±ÆÉæèAfobOR[hðæèÈPÉüµLqÅ«éæ¤ÉÈé±Æªí©èÜ·ËB 7.4@enum é¾ÅÌ]ªÈJ} @zñðú»·éÍAint i[ ] = { 1, 2, 3, } Ìæ¤ÉÅãÌ]ªÈJ}ͳêĢܵ½Bµ©µAenum é¾ÅÍ enum { a, b, c,} Ìæ¤ÉÅãÉ]ªÈJ}ðüêéÆG[ÉÈÁĢܵ½B¡ñÌ C ¾êÅÍA±Ìæ¤È enum é¾ÅÌ]ªÈJ}ª³êéæ¤ÉÈèܵ½B 7.5@inline Öè` @C++ Éà é@\ª C Éà±ü³êܵ½B»Ì@\Í inline Öè`Ì@\Å·B¡ÜÅÌ C ¾êÅÍAÖÌæ¤ÉLqÅ«Aµ©à¬ÉÄÑo¹éæ¤Éµ½¢êÉÍAÖ^}Nðgp·éKvª èܵ½Bµ©µAÖ^}NÅÍ^¸ªÅ«È¢ãAg¢ûÉÍæÁÄÍ\ªÅ«È¢Êð±±Æà èܵ½B @¡ñ±ü³êé inline @\ðg¤ÆA^¸à³êA³çÉÊíÌÖƯ¶]¿ªÈ³êA©Â¬ÉÀsÅ«éÖðè`·é±ÆªÅ«Ü·Bg¢ûÍA½¾PÉÖð inline L[[hðgÁÄCü·é¾¯Å·Bá¦ÎAinline void swap(int *a1, int *a2){...} Å·B½¾µOP[WðÂÖÉεÄÍAinline t«ÌÖé¾ðsÁ½ç»Ìè`ð¯¶|óPÊŵÈÄÍÈçÈ¢AC³Â\ÈÃIL¯õ½ðÂè`ðÓñÅÍÈçÈ¢AàP[Wð¯ʼÖÌQÆðÓñÅÍÈçÈ¢AÆ¢¤§ñª èÜ·Bܽ main ÖÍ inline Cüð·é±ÆªÅ«Ü¹ñB @inline è`ÍRpCÉηéqgÅ èARpCÍK¸µà¬ÄÑoµR[h𶬷éÆÍÀèܹñB 7.6@restrict |C^ @C ¾ê;êƵÄÍ|C^ð©Èè©RÉg¦é¾êÅ·B»ÌÊAvO}ª|C^ðãèÉg¦Î¢vOð¯éæ¤ÉÈèܵ½Bµ©µ»ÌêûÅA|C^ÌʼðÈPÉìé±ÆªÅ«éæ¤ÉÈÁĵÜÁ½ÌÅARpCªf[^ðÍâÅK»R[h𶬷éÌáQÉÈÁīܵ½Bá¦ÎAÌáð©Ä¾³¢B
@(1)̪Ìsumup ÖÍ array1 É array2 Ìàeð n ª«µÞÖÅ·B½¾µ±±Å±ÌvOÅÍ n Ìlª 4 Ì{Å array1 Æ array2 ͯ¶àeðwµÄ¢È¢ÄÑoµµ©µÈ¢Æ¼èÅ«é±ÆƵܷB·éÆ»êÉ뵀 SIMD ½ßðgpÅ«é CPU ãÌAZuÌR[hÌ[vªÍ (2) Ìæ¤ÉÅK»·é±ÆªÅ«Ü·Bܸ array1 Ì 4 vfªð r1 WX^Éi[µÜ·B»µÄ¯lÉ array2 Ì 4 vfªð r2 WX^ÉüêA»êð r1 ÆÁZµÄAÊÆÈé r1 ð array1 ɫߵܷB½Á½ê½áÅzñ 4 vfªÌÁZªÅ«AܽÊÆµÄ n/4 ñÌ[vÅvZÅ«éÌűÌR[hÍø¦IÅ·B @µ©µ»ÀÉÍRpCͱÌæ¤Èø¦IÈR[h𶬷é±ÆÍūܹñŵ½BȺÈçÎARpCÍ array1 Æ array2 ª¯¶àeðwµÄ¢È¢Æ¼èµÄ梱ÆÍÜÁ½mèܹñBµ½ªÁÄA(3) Ìæ¤ÈÄÑoµÉàηé (2) æèàòéR[h (4) 𶬷éKvª èÜ·B(4) ÍzñÌvfê¸ÂÁZµÄ¢ÌÅ n ñÌ[vÆÁZªsíêé±ÆÉÈèÜ·B
(3) ÌÄÑoµã̳µ¢ array ÌlÍAÂÜè (4) ÅvZµ½ÊÍ { 1, 2, 4, 6, 9, 12, } ÉÈé͸ŷBµ©µA(2) ÌR[hÅÍA±ÌlÍA{ 1, 2, 4, 6, 8, 10, } ÉÈÁĵܢA(4) ÅvZµ½ÊÌlÆÙÈÁ½lðÔ·±ÆÉÈèÜ·B±Ìæ¤ÉA»ÝÌ C ¾êÅÍRpCÉæéðÍâR[h¶¬ðW°évöªÜÜêĢܷB @¡ñÌ C ¾ê©çpÅ«éæ¤ÉÈé restrict CüqÍAOqµ½æ¤È|C^ª¯¶àeðwµÄ¢È¢Æ¢¤îñðRpCÉñ·é±ÆªÅ«Ü·Brestrict Í|C^¾¯ðCü·é½ßÉp·é±ÆªÅ«Ü·B(1) É restrict Cüµ½R[hð (5) ɦµÜ·B
@(5) ÅÍvZÉ array1 Æ array2 ª¯ÁµÄ¯¶àeðwµÄ¢È¢Æ¢¤îñðRpCÉ^¦Ä¢Ü·Bµ½ªÁÄARpCͱÌîñð³É (2) Ìæ¤ÈR[h𶬷é±ÆªÅ«Ü·B±Ìæ¤È±Æ©çA(6) Ìæ¤ÈÄÑoµÍ³µ®ìµÜ·ªA(7) Ìæ¤ÈÄÑoµðµ½êÉÍA¾êIÉÍ¢è`Ì®ìÉÈèA½Ôñ³µ¢Êðc³È¢Åµå¤B @ȨACuÌÌ|C^ðøÉ¡ÌÖvg^Cvª restrict Cüqt«Ìé¾ÉÏX³êܵ½B 7.7@Ïé¾ÆÀsR[hÌÊuÖW @Ïðg¤ÉÍAQÆ·éOÉé¾ð·éKvª èÜ·B±Ì½ß]Ì C ¾êÅÍA»ÌR[hðÜÞubNÌæªÅÜÆßÄsíȯêÎÈèܹñŵ½B¡ñÌVµ¢ C ¾êÅÍAC++ ¾êƯ¶æ¤ÉAubNÌæªÆ¢¤ÊuÉçêé±ÆÈAQÆ·éOÉDZÅàé¾µÄæ¢Æ¢¤±ÆÉÈèܵ½BXR[vÍA»Ì龳꽼ã©çJn³êÜ·B @Ϫú»t«Åé¾³êÄ¢éê(á¦ÎAint i = 3)A§äª»Ìé¾ðÊß·éêÉÌÝú»³êÜ·B൧äªÊߵȢê»ÌlÍsèÅ·BܽOñ»±ðÊßµú»³ê½ãAÄÑ[v©½©Å¯¶é¾ÉâÁ½½¯êÇàA»Ì龪ðòÑz¦½êÅàAÈOãü³ê½lÍYêçêĨèAsèlÆÈèÜ·B @ܽÂÏ·zñðé¾µ½êA»Ìé¾ðòÑz·OûWvÍÖ~³êĢܷBȺÈçÎAòÑz³êéÆAm۷׫Kvʪí©çÈ¢©çÅ·B @³çÉAfor ¶àg£³êܵ½Bfor ¶ÍAfor( [1]; ...; ...) { ... } Ìæ¤ÉÊíp¢Ü·ªAÈñÆ [1] ̪É龪¨¯éæ¤ÉÈèܵ½BÂÜè C++ ¾êÅÌƯlÉAfor(int i = 0; i < 100; i++){ ... } Ìæ¤ÉLq·é±ÆªÅ«éæ¤ÉÈèܵ½BȨ±Ì i ªLøÈÌͱÌ[vÌÍÍྯŷBܽg¦éÏÍAauto Ï© register Ͼ¯ÅAstatic ÏÈÇÍgpūܹñB 7.8@w¦t«Ìú»q (Designated Initializer) @¢æ¢æAw¦t«Ìú»q (Designated Initializer) ÌoêÅ·B»ÝÌ C ¾êÅÍ\¢Ìâzñð 究ßú»·éÉÍAnßÌvf©ç·×ÄwèµÄú»·éû@µ© èܹñŵ½B»ÌÊƵÄAüÍÍñíÉåÏÅA©Â©ÃçÈèÜ·B
@»±Å±ÌV@\ªoêÅ·B±Ì@\ðgÁÄ«¼·ÆÌæ¤ÉÈèÜ·B
@ñíÉ·Á«èA©â·Èèܵ½B±Ìæ¤ÉAw¦t«Ìú»qÍú»ÉzñÌvfâo¼ðwè·é±ÆÅAí©èâ·ú»ðs¦éæ¤É·éàÌÅ·B»±ÅܸAzñÌw¦t«Ìú»qðg¤ÉÍAvfðwèµÄú»µÜ·Bá¦ÎAzñÌ 3 ÔÚÌvfðú»µ½¢ÉÍA [3] = ..., Æ¢¤æ¤ÉLqµÜ·Bܽ\¢Ìâ¤pÌðú»µ½¢ÉÍA.o¼ = ..., Ìæ¤Éwè·é±ÆÅú»ðs¦Ü·BȨAstatic ÅÈ¢Ïðú»·éêÉÍAúlƵÄèÅÍÈ¢lAá¦Î¼ÌÏðQƵ½®ðwè·éAÆ¢Á½±ÆªÅ«Ü·B 7.9@¡e (Compound Literal) @¢ɱÌ@\ÌoêÅ·BF³ñÍÌæ¤ÈLqð·éÉA±êÍÊ|¾ÆvÁ½±ÆÍȢŵ天?
@Ö PutPixel ÌøÉPÈéèÆµÄ point_t ^Ìlðnµ½¢Bµ©µ»ÝÌ C ¾êÅͻ̽ßÉÏð龵ijçÉlðãü·éKvª èÜ·Bµ©µA±ÌV@\ðg¦Î±êÍÌæ¤É«¼·±ÆªÅ«Ü·B
@IuWFNg^ܽÍ嫳Ìwè³µÌzñð ( ) ÌÉLqµÄÉ { } ðLq·é±ÆÅ¡e (Compound Literal) ðìé±ÆªÅ«Ü·B{ } ÌÍáÉ éƨèw¦t«Ìú»qðgÁ½ú»àÂ\Å·Bܽ (int[ ]){1, 2, 3, 4} Ìæ¤Èzñèðìè¼ÚÖøƵÄn·±ÆàÂ\Å·B½¾µÂÏ·zñÌèÍ¡eÅìé±ÆÍūܹñB 7.10@Ið¶Æ½¶ÌubN» @¡xÌ C ¾êÅÍA¡e (Compound Literal) ̱üɺ¢AIð¶(if ¶ÈÇ)A½¶(for ¶ÈÇ)̵¢ªÏXÉÈèܵ½BïÌIÉÍ»êçÌ¶Í { } ÅÍÜêÄ¢éƵĵíêé±ÆÉÈèܵ½BǤ¢¤Ó¡Åµå¤? áð¦µÜ·B
@(1)Ìæ¤É if ¶Å¡eðgpµÄA|C^ÏÉ»êðãüµÄ¢Ü·B³ÄA(*) ÅwµÄ¢éàÌÍ¢Á½¢Èñŵå¤BÀÍA¡xÌ C ¾êÅÍ (2) Ìæ¤ÉAÔŦ³ê½ubNªÃÙIɨ¬ÈíêÜ·B»ÌÊƵÄAa à b àwµÄ¢éàÌÌÛت³¢±ÆªÛسêÜ·B±êÍA«Ì¾êÌgpðüèµ½Ó}µÈ¢Êðª«N±³È¢æ¤É±üµ½»¤Å·B @½¾±ê̱üÉæèAù¶ÌvOÌÓ¡ªÏíÁÄµÜ¤êª èÜ·B(3) ð©Ä¾³¢B
(3) ÅÍnßÉ a==0, b==1 ÆµÄ enum é¾ðµÄ¢Ü·BÖ g ÌÅÍAsizeof ÌIyhÌÅ b==0, a== 1 ÆµÄ enum é¾ðµÄ¢Ü·Bµ½ªÁÄ]Ì C ¾êÅÍAenum{b,a} ÌXR[v͸ÁƱµÄ¢éÌÅAÖ g Í 0 ðÔ·±ÆÉÈèÜ·Bµ©µ¡xÌ C ¾êÅÍAif ¶S̪ubNƵĢíêĢܷBµ½ªÁÄAenum{b,a} Í if ¶ªIíÁ½ãÍ©é±ÆªÅ«Ü¹ñBµ½ªÁÄAO[oÈ enum{a,b} ª©¦AÊƵÄÖ g Í 1 ðԵĵܢܷB |
|
| ||||
\
-
ì
-
Ó
-
NÉ¢Ä
-
404 G[É¢Ä
(c)1999-2014 seclan. All rights reserved. |