³ª´Â Á÷¾÷»ó ´Ù¾çÇÑ Ç÷§Æû, ´Ù¾çÇÑ OS, ´Ù¾çÇÑ ±×·¡ÇÈ Ä¨¿¡ ³»°¡ ¸¸µç ¶óÀ̺귯¸®¸¦ Æ÷ÆÃÇÏ´Â ÀÏÀ» ÇÑ´Ù. ±×·¡¼ ¸¹Àº Á¾·ùÀÇ C ÄÄÆÄÀÏ·¯¸¦ »ç¿ëÇÏ°í ÀÖ´Ù. ¿ì¸®°¡ º° »ý°¢¾øÀÌ ¸¸µå´Â Äڵ忡 ÇÔÁ¤ÀÌ ¼û¾î ÀÖ´Â °æ¿ì°¡ Àִµ¥, ³ª´Â ¸î ´Þ Àü¿¡ ¾Æ·¡ÀÇ ¹®Á¦ ¶§¹®¿¡ ¸çÄ¥À» µð¹ö±ë ÇÑ ÀûÀÌ ÀÖ´Ù. ÀçÇöÇϱâ À§ÇØ Áß¿ä ºÎºÐÀÇ ¼Ò½º¸¸ µû·Î ¶¼¾î ³»¾î¼ ½ÇÇà °¡´ÉÇÏ°Ô Çغ¸¾Ò´Ù.
#include <stdio.h>
int main() { unsigned char buffer[2] = {0, 0}; unsigned char* pByte = buffer;
*pByte = 1 + *pByte++;
printf("%d, %d\n", buffer[0], buffer[1]);
return 0; }
¾ÆÁÖ ´Ü¼øÇÑ ÄÚµå´Ù. ±×³É ¹öÆÛÀÇ °ªÀ» Áõ°¡½ÃÅ°°Å³ª ±× °ªÀ» ´õÇϰųª ÇÏ´Â °ÍÀε¥, ÀÌ°ÍÀÌ ¸ÖƼ Ç÷§Æû¿¡ À̽ĵǾúÀ» ¶§ ±× °á°ú°¡ Ç×»ó ÀÏÁ¤ÇÏÁö ¾Ê´Ù´Â °ÍÀÌ ±× ¹®Á¦´Ù. VC++¿¡¼ÀÇ °á°ú°¡ ´Ù¸£°í mips¿ë g++¿¡¼ °á°ú°¡ ´Ù¸£´Ù. ±×¸®°í ¾Æ·¡ÀÇ ¿¹´Â ÀÏ¹Ý linuxÀÇ g++¿¡¼µµ ±× °á°ú°¡ ´Þ¶óÁø´Ù´Â °ÍÀÌ´Ù.
ÀÌ°ÍÀº debianÀÇ g++ 4.0.1¿¡¼ÀÇ °á°úÀÌ´Ù. ¹®Á¦´Â ¾ø´Ù.
% g++ --version g++ (GCC) 4.0.1 (Debian 4.0.1-2) Copyright (C) 2005 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
% g++ q.cpp % ./a.out 1, 0 % g++ q.cpp -O3 % ./a.out 1, 0
ÀÌ°ÍÀº cygwinÀÇ g++ 3.4.4¿¡¼ÀÇ °á°úÀÌ´Ù. ÀÌÁ¦ ¹®Á¦°¡ ³ªÅ¸³ª±â ½ÃÀÛÇÑ´Ù. (LinuxÀÇ g++ ÄÄÆÄÀÏ·¯ ¹öÀüÀÌ ¿Ã¶ó°¡ ¹ö·Á¼ cygwinÀ» ¾´ °Í»ÓÀÌÁö ÀÌÀü¿¡ ±ò·È´ø 3.4.x ¹öÀüµµ °°Àº ¹®Á¦°¡ ÀÖ¾ú´Ù.)
$ g++ --version g++ (GCC) 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125) Copyright (C) 2004 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ g++ q.cpp $ ./a.exe 1, 0 $ g++ q.cpp -O3 $ ./a.exe 0, 1
ºÐ¸í °°Àº ¼Ò½º¸¦ °°Àº ¹öÀüÀÇ ÄÄÆÄÀÏ·¯·Î ÄÄÆÄÀÏÇÏ¸é¼ ´ÜÁö optimization ¿É¼Ç¸¸ µû·Î ÁáÀ» »ÓÀε¥ ±× °á°ú°¡ ´Ù¸£°Ô ³ªÅ¸³´Ù. ÀÌ°ÍÀº È®½ÇÈ÷ ¹®Á¦°¡ ÀÖ°í ÀÌ·± ·ùÀÇ ¹ö±×´Â Á¤¸» ¹ß°ßÇϱⰡ ¾î·Æ´Ù. ÀÌ°ÍÀº ÄÄÆÄÀÏ·¯ÀÇ ¹ö±×¶ó±â º¸´Ù´Â C ÄÄÆÄÀÏ·¯ÀÇ implementationÀÇ ¹®Á¦À̸ç ÀÌ·± ºÎºÐÀº ÇÁ·Î±×·¥°¡ ¾Ë¾Æ¼ ÇÇÇØ¾ß ÇÑ´Ù. (third party compilerÀÇ °æ¿ì ´õ ÀÌ·± ¹®Á¦°¡ ¸¹¾Æ º¸ÀδÙ. ÇÏÁö¸¸ ´ÙÇེ·´°Ôµµ VC++¿¡¼¸¸ ¸ðµç ÀÏÀ» ÇÒ »ç¶÷À̶ó¸é ÀÌ ±ÛÀº ¹«½ÃÇصµ µÉ °Í °°´Ù.)
1. Á×À½Ãµ»ç £º'¾Ö¸ÅÇÏ¸é ±×³É °ýÈ£¸¦ »ç¿ëÇÑ´Ù'°¡ Á¤´äÀΰ¡¿ä.. ^^ (½ÇÁ¦·Î Àú´Â ±×·¸°Ô ÇÔ) [10/27]
2. ¾È¿µ±â £ºÀÌ °æ¿ì¿¡´Â ÈÄÀ§Áõ°¨ ¿¬»êÀÚ¸¦ R-value ¿¬»êÀÌ ³¡³ ÈÄ ÇÒ °ÍÀΰ¡ L-value ¿¬»êÀÌ ³¡³ ÈÄ¿¡ ÇÒ °ÍÀΰ¡¿¡ ´ëÇÑ Á¤Ã¥ÀÇ ¹®Á¦ÀÔ´Ï´Ù. ÀϹÝÀûÀÎ °æ¿ì(VC++ Æ÷ÇÔ) L-value ¿¬»ê±îÁö ³¡³ ÈÄ Áõ°¨¿¬»êÀ» ÇÏÁö¸¸ ÄÄÆÄÀÏ·¯¿¡ µû¶ó¼´Â Á¤Ã¥ÀÌ ´Ù¸£´Ù´Â °ÍÀÔ´Ï´Ù. ÀÌ·± ¹®Á¦¸¦ ȸÇÇÇÏ·Á¸é °á±¹ L-value ÂÊ¿¡ Áõ°¨¿¬»êÀÚ¸¦ ³Ö¾î¾ß ÇÑ´Ù´Â... [10/27]
3. Rupaus £ºÀúµµ ÀÌ·¸°Ô ÄÄÆÄÀÏ·¯¶§¹®¿¡ ¹ö±×·Î °í»ýÇÑÀûÀÌ ¸¹¾Æ¼ ±× µÚ·Î´Â Çѹ®Àå¿¡ °ãÄ¡°Ô ¾È¾²°í ±×³É ¼ø¼´ë·Î Ç®¾î¾¹´Ï´Ù. ±æÀÌ°¡ ´Ã¾î³ª°í ÇÏ´Â°Ç Á» ±×·¸Áö¸¸ ±×°Ô ¼ÓÆíÇÑ ¸éÀÌ ÀÖ´õ±º¿ä¤Ð_¤Ì [10/27]
4. ¹°µ¶ £ºÀü ¸Ç³¯ Çò°¥¸®´Â°Ô... if (pThing != NULL && pThing->some == 123) À̶õ ¹®ÀåÀ» ½áµµ µÇ´ÂÁö.. pThingÀÌ NULL À϶§, ¿ÞÂÊ ºñ±³¹®ºÎÅÍ º¸¸é »ó°ü¾øÁö¸¸, °¡²û ¿À¸¥ÂʺÎÅÍ º¸´Â ÄÄÆÄÀÏ·¯µµ ÀÖ´Ù´Â ¼Ò¹®À» µé¾î¼.... -> ¿¹Àü¿¡ Ã¥¿¡¼ º¸±â·Î´Â ¹«Á¶°Ç ¿ÞÂʺÎÅͶó°í º» °Í°°°í, borland °è¿¿¡¼´Â 'if¹® ¾ÈÀÇ ¸ðµç Á¶°ÇÀ» ´Ù È®ÀÎÇÏ°í ³Ñ¾î°£´Ù'¶ó´Â ÄÄÆÄÀÏ ¿É¼ÇÀÌ ÀÖ¾ú´ø °É·Î ±â¾ïÇÕ´Ï´Ù. ±×°Ô ÄÑÁ® ÀÖÀ¸¸é À§ÇèÇÑ ÄÚµåÁÒ. (ÇÏÁö¸¸ ±â¾ïÀ̶õ Ç×»ó ºÎÁ¤È®ÇÒ ¼ö ÀÖ´Â °ÍÀÌ´Ï....) [10/27]
|
|