タグ

c++とC言語に関するteppochanのブックマーク (1)

  • while(1){LOVE++;}を最適化 - duost

    最近ツイッターで "while(1){LOVE++}"と書き込まれてる指輪があって、 そのソースは最適化でLOVEが消えてただの無限ループになる云々という話があったので検証。 http://togetter.com/li/144840 用意したソースはこちら。 int main() { int LOVE = 0; while(1){LOVE++;} } それじゃアセンブラを見てみましょ。 まずは最適化抜き。 gcc -O0 -s hoge.c .file "hoge.c" .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp subl $16, %esp movl $0, -4(%ebp) ;LOVE=0 .L2: addl $1, -4(%ebp) ;LOVE++ jmp .L2 ;JUMP TO

    while(1){LOVE++;}を最適化 - duost
    teppochan
    teppochan 2011/06/15
    これって愛を使わなかったから消えたの?
  • 1