{"id":783,"date":"2008-09-06T16:52:41","date_gmt":"2008-09-06T07:52:41","guid":{"rendered":"http:\/\/terzeron.com\/?p=783"},"modified":"2008-09-06T16:52:41","modified_gmt":"2008-09-06T07:52:41","slug":"cc-%eb%b3%80%ec%88%98-%ec%b4%88%ea%b8%b0%ed%99%94%ec%9d%98-%ec%98%a4%eb%b2%84%ed%97%a4%eb%93%9c","status":"publish","type":"post","link":"https:\/\/terzeron.com\/?p=783","title":{"rendered":"[C\/C++] \ubcc0\uc218 \ucd08\uae30\ud654\uc758 \uc624\ubc84\ud5e4\ub4dc"},"content":{"rendered":"<p>\ub2e4\uc74c\uc758 \ub450 \ucf54\ub4dc \uc870\uac01,<\/p>\n<pre class=\"brush: xml\">char * arr[100];<\/pre>\n<p>\uc640<\/p>\n<pre class=\"brush: xml\">char * arr[100] = { (char *) 0, };<\/pre>\n<p>\ub294 \uc2ec\uac01\ud55c \uc131\ub2a5 \ucc28\uc774\ub97c \ubcf4\uc778\ub2e4. \uc790\uc8fc \ud638\ucd9c\ub418\ub294 \ud568\uc218\ub098 loop \uc548\uc5d0 \uc774\ub7f0 \ucf54\ub4dc\ub97c \ub123\uc73c\uba74, \uc131\ub2a5 \uc800\ud558\uac00 \ud06c\uac8c \ub098\ud0c0\ub0a0 \uac83\uc774\ub2e4.<\/p>\n<p>\ube44\ub85d \ucf54\ub4dc \uc0c1\uc73c\ub85c\ub294 \ubc30\uc5f4\uc758 \uccab\ubc88\uc9f8 element\ub9cc \ucd08\uae30\ud654\ud558\ub294 \uac83\uc73c\ub85c \ubcf4\uc774\uc9c0\ub9cc, \uc2e4\uc81c\ub85c\ub294 <strong>\ubc30\uc5f4\uc758 \ubaa8\ub4e0 element\uc5d0 \ub300\ud574\uc11c \ucd08\uae30\ud654<\/strong>\ud558\ub294 \uc791\uc5c5\uc774 \uc774\ub8e8\uc5b4\uc9c4\ub2e4. assembly code \uc218\uc900\uc5d0\uc11c\ub294 memset\uc73c\ub85c \ubc30\uc5f4\uc774 \ucc28\uc9c0\ud558\ub294 \uba54\ubaa8\ub9ac \uacf5\uac04\uc744 \ubaa8\ub450 0\uc73c\ub85c set\ud558\ub294 \uac83\uacfc \ub3d9\uc77c\ud558\ub2e4.<\/p>\n<p>\ucef4\ud30c\uc77c\ub7ec\uac00 \ucd5c\uc801\ud654(optimization)\ub97c \ud558\uc9c0 \uc54a\uc740 \uc0c1\ud0dc\uc5d0\uc11c\ub294(-00), \ub2e4\uc74c\uacfc \uac19\uc740 assembly code\uac00 \uc0dd\uc131\ub41c\ub2e4. (GCC 3.4.6, x86_64)<\/p>\n<pre class=\"brush: xml\"> leaq -800(%rbp), %rdi\nmovl $800, %edx\nmovl $0, %esi\ncall memset<\/pre>\n<p>\uc774 \ucf54\ub4dc\ub294 memset\uc744 \ud638\ucd9c\ud558\uae30 \uc804\uc5d0 \uccab\ubc88\uc9f8 argument\ub85c \uc774 arr \ubc30\uc5f4\uc758 \uc8fc\uc18c\ub97c 64\ube44\ud2b8\ub85c \ud574\uc11c \uc800\uc7a5\ud558\uace0, \ub450\ubc88\uc9f8 argument\ub85c 0\uc758 \ucd08\uae30\uac12\uc744, \uc138\ubc88\uc9f8 argument\ub85c 800\ubc14\uc774\ud2b8(64\ube44\ud2b8 * 100\uac1c)\uc758 \uae38\uc774\ub97c \uc9c0\uc815\ud55c \ub2e4\uc74c, memset\uc744 \ud638\ucd9c\ud558\ub294 \uac83\uc774\ub2e4. C \ucf54\ub4dc\ub85c\ub294 \ub2e4\uc74c\uacfc \uac19\ub2e4.<\/p>\n<pre class=\"brush: xml\">memset(arr, 0, 800);<\/pre>\n<p>\ucd5c\uc801\ud654 \uc218\uc900\uc744 \ub192\uc774\ub354\ub77c\ub3c4 \uc57d\uac04\uc758 assembly code \uc0c1\uc73c\ub85c \ucc28\uc774\uac00 \uc788\uae34 \ud558\uc9c0\ub9cc, \uacb0\uacfc\uc801\uc73c\ub85c\ub294 \ubc30\uc5f4\uc758 \uba54\ubaa8\ub9ac \uacf5\uac04 \uc804\uccb4\uc5d0 \ub300\ud55c \ucd08\uae30\ud654\uac00 \uc218\ud589\ub41c\ub2e4.<\/p>\n<p>\ucc38\uace0\ub85c \ucd5c\uc801\ud654 \uc218\uc900\ubcc4\ub85c assembly code\ub97c \uc694\uc57d\ud574\ubcf8\ub2e4. \ucf54\ub4dc \uc21c\uc11c\uac00 \uc870\uae08\uc529 \ub4a4\ubc14\ub00c\uc5b4 \uc788\uace0, opcode\uac00 \uc870\uae08\uc529 \ub2e4\ub974\ub2e4.<\/p>\n<p>-O1<\/p>\n<pre class=\"brush: xml\"> movq %rsp, %rdi\nmovl $800, %edx\nmovl $0, %esi\ncall memset<\/pre>\n<p>-O2, -O3<\/p>\n<pre class=\"brush: xml\"> movl $800, %edx\nxorl %esi, %esi\nmovq %rsp, %rdi\ncall memset<\/pre>\n<p>-O2, -O3\uc758 \uc0c9\ub2e4\ub978 \uc810\uc740, 0\uac12\uc744 register\uc5d0 \uc800\uc7a5\ud558\uae30 \uc704\ud574 0\uac12\uc744 \uc9c1\uc811 \uc800\uc7a5\ud558\ub294 \uac8c \uc544\ub2c8\ub77c \ud574\ub2f9 register\ub97c xor\ub85c \ud604\uc7ac set\ub41c \uac12\uc744 reset\ud558\ub294 \ubc29\uc2dd\uc744 \uc0ac\uc6a9\ud55c\ub2e4\ub294 \uc810\uc774\ub2e4.<\/p>\n<div class=\"fb-background-color\">\n\t\t\t  <div \n\t\t\t  \tclass = \"fb-comments\" \n\t\t\t  \tdata-href = \"https:\/\/terzeron.com\/?p=783\"\n\t\t\t  \tdata-numposts = \"100\"\n\t\t\t  \tdata-lazy = \"true\"\n\t\t\t\tdata-colorscheme = \"light\"\n\t\t\t\tdata-order-by = \"time\"\n\t\t\t\tdata-mobile=true>\n\t\t\t  <\/div><\/div>\n\t\t  <style>\n\t\t    .fb-background-color {\n\t\t\t\tbackground: #ffffff !important;\n\t\t\t}\n\t\t\t.fb_iframe_widget_fluid_desktop iframe {\n\t\t\t    width: 100% !important;\n\t\t\t}\n\t\t  <\/style>\n\t\t  ","protected":false},"excerpt":{"rendered":"<p>\ub2e4\uc74c\uc758 \ub450 \ucf54\ub4dc \uc870\uac01, char * arr[100]; \uc640 char * arr[100] = { (char *) 0, }; \ub294 \uc2ec\uac01\ud55c \uc131\ub2a5 \ucc28\uc774\ub97c \ubcf4\uc778\ub2e4. \uc790\uc8fc \ud638\ucd9c\ub418\ub294 \ud568\uc218\ub098 loop \uc548\uc5d0 \uc774\ub7f0 \ucf54\ub4dc\ub97c \ub123\uc73c\uba74, \uc131\ub2a5 \uc800\ud558\uac00 \ud06c\uac8c \ub098\ud0c0\ub0a0 \uac83\uc774\ub2e4. \ube44\ub85d \ucf54\ub4dc \uc0c1\uc73c\ub85c\ub294 \ubc30\uc5f4\uc758 \uccab\ubc88\uc9f8 &hellip; <a href=\"https:\/\/terzeron.com\/?p=783\">\uacc4\uc18d \uc77d\uae30 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_sitemap_exclude":false,"_sitemap_priority":"","_sitemap_frequency":"","footnotes":""},"categories":[13],"tags":[],"class_list":["post-783","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/terzeron.com\/index.php?rest_route=\/wp\/v2\/posts\/783","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/terzeron.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/terzeron.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/terzeron.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/terzeron.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=783"}],"version-history":[{"count":0,"href":"https:\/\/terzeron.com\/index.php?rest_route=\/wp\/v2\/posts\/783\/revisions"}],"wp:attachment":[{"href":"https:\/\/terzeron.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=783"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/terzeron.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=783"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/terzeron.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=783"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}