C/C++のクイズ

September 17th, 2011

こんなコードが同僚から送られてきた。

#include <iostream>
 
int a[] = {1, 12, 13,2};
int b[] = {2, 12, 23,2};
 
int main()
{
  int c = 3[b][a];
  std::cout << c;
  return 0;
}

結果が気になる人はこちらcode pad

以下ダンプ

.globl a
        .data
        .align 4
        .type   a, @object
        .size   a, 16
a:
        .long   1
        .long   12
        .long   13
        .long   2
.globl b
        .align 4
        .type   b, @object
        .size   b, 16
b:
        .long   2
        .long   12
        .long   23
        .long   2
        .text
.globl main
        .type   main, @function
main:
.LFB963:
        .cfi_startproc
        pushl   %ebp
        .cfi_def_cfa_offset 8
        movl    %esp, %ebp
        .cfi_offset 5, -8
        .cfi_def_cfa_register 5
        andl    $-16, %esp
        subl    $32, %esp
        movl    b+8, %eax
        movl    a(,%eax,4), %eax
        movl    %eax, 28(%esp)
        movl    28(%esp), %eax
        movl    %eax, 4(%esp)
        movl    $_ZSt4cout, (%esp)
        call    _ZNSolsEi
        movl    $0, %eax
        leave
        .cfi_restore 5
        .cfi_def_cfa 4, 4
        ret
        .cfi_endproc

Leave a Reply

*