The difference between the "gcc -x c" and "gcc -x C ++" assemblies

I have the following code in the main.c file:

int main() {
    int i;
    for (i = 0; i < 5; i++) {
    }

    return 0;
}

When I compile this using gcc -x c -m32 -S -O0 -o main.s main.c(on the 64-bit version of Fedora 16), I get this output:

    .file   "main.c"
    .text
    .globl  main
    .type   main, @function
main:
.LFB0:
    .cfi_startproc
    pushl   %ebp
    .cfi_def_cfa_offset 8
    .cfi_offset 5, -8
    movl    %esp, %ebp
    .cfi_def_cfa_register 5
    subl    $16, %esp
    movl    $0, -4(%ebp)
    jmp .L2
.L3:
    addl    $1, -4(%ebp)
.L2:
    cmpl    $4, -4(%ebp)
    jle .L3
    movl    $0, %eax
    leave
    .cfi_restore 5
    .cfi_def_cfa 4, 4
    ret
    .cfi_endproc
.LFE0:
    .size   main, .-main
    .ident  "GCC: (GNU) 4.6.2 20111027 (Red Hat 4.6.2-1)"
    .section    .note.GNU-stack,"",@progbits

However, when I use gcc -x c++ -m32 -S -O0 -o main.s main.c, I get the same output, with the exception of these lines:

.L2:
    cmpl    $4, -4(%ebp)
    setle   %al
    testb   %al, %al
    jne .L3

My question is: why does it use setleand testbinstead jlein C ++ code? Is it more efficient?

PS In addition, is there a way to get rid of these directives .cfi_*at the output of the assembly?

+3
source share
1 answer

, , , . clang C ++, :

$ cp example.c example.cpp
$ clang -o exampleC example.c
$ clang++ -o exampleC++ example.cpp
$ otool -tV exampleC > C
$ otool -tV exampleC++ > C++
$ diff C C++
1c1
< exampleC:
---
> exampleC++:
$

gcc g++ , .

+2

All Articles