Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

c code story

Name: Anonymous 2011-12-25 0:50

this one time i went to these guys and i wall all "hey guys check out my c code" and they were all "dude your code sucks" and i was all "no dude nothing is wrong with my code" and then the guy was all "you used a break statement in nested while loops" so i said to him i says "dude thats totally legit" and hes all "dude your noob programmer if you compile that in a very specific way then there is a chance that the code wont work" so i told him right to his face that he is a faggot and wrong because my code worked and i didn't care if it wouldn't work compiled that way because maybe i won't compile it that way

and thats my story i hope you enjoyed it

Name: Anonymous 2011-12-26 0:21

>>33
also to add some application to the loops:

[ @ ~/host/prog/story ] $ cat st.c
#include <stdio.h>

void forloop(void)
{
    int i;
    for(i=0;i!=8;i+=2)
        puts(">>33 is a faggot");
}

void whileloop(void)
{
    int i = 0;
    while(1){
        puts(">>33 is a faggot");
        i+=2;
        if(i == 8)
            break;
    }
}


int main()
{
    forloop();
    whileloop();
}



gcc -S st.c

[ Mon Dec 26 12:19:33 ]
[ @ ~/host/prog/story ] $ cat st-O0.s
    .file    "st.c"
    .section    .rodata
.LC0:
    .string    ">>33 is a faggot"
    .text
.globl forloop
    .type    forloop, @function
forloop:
.LFB0:
    .cfi_startproc
    pushq    %rbp
    .cfi_def_cfa_offset 16
    movq    %rsp, %rbp
    .cfi_offset 6, -16
    .cfi_def_cfa_register 6
    subq    $16, %rsp
    movl    $0, -4(%rbp)
    jmp    .L2
.L3:
    movl    $.LC0, %edi
    call    puts
    addl    $1, -4(%rbp)
.L2:
    cmpl    $8, -4(%rbp)
    jne    .L3
    leave
    ret
    .cfi_endproc
.LFE0:
    .size    forloop, .-forloop
.globl whileloop
    .type    whileloop, @function
whileloop:
.LFB1:
    .cfi_startproc
    pushq    %rbp
    .cfi_def_cfa_offset 16
    movq    %rsp, %rbp
    .cfi_offset 6, -16
    .cfi_def_cfa_register 6
    subq    $16, %rsp
    movl    $0, -4(%rbp)
.L7:
    addl    $2, -4(%rbp)
    cmpl    $8, -4(%rbp)
    je    .L10
.L6:
    movl    $.LC0, %edi
    call    puts
    jmp    .L7
.L10:
    nop
.L9:
    leave
    ret
    .cfi_endproc
.LFE1:
    .size    whileloop, .-whileloop
.globl main
    .type    main, @function
main:
.LFB2:
    .cfi_startproc
    pushq    %rbp
    .cfi_def_cfa_offset 16
    movq    %rsp, %rbp
    .cfi_offset 6, -16
    .cfi_def_cfa_register 6
    call    forloop
    call    whileloop
    leave
    ret
    .cfi_endproc
.LFE2:
    .size    main, .-main
    .ident    "GCC: (Debian 4.4.5-8) 4.4.5"
    .section    .note.GNU-stack,"",@progbits



gcc -O3 -S st.c

[ Mon Dec 26 12:19:44 ]
[ @ ~/host/prog/story ] $ cat st.s
    .file    "st.c"
    .section    .rodata.str1.1,"aMS",@progbits,1
.LC0:
    .string    ">>33 is a faggot"
    .text
    .p2align 4,,15
.globl whileloop
    .type    whileloop, @function
whileloop:
.LFB12:
    .cfi_startproc
    subq    $8, %rsp
    .cfi_def_cfa_offset 16
    movl    $.LC0, %edi
    call    puts
    movl    $.LC0, %edi
    call    puts
    movl    $.LC0, %edi
    call    puts
    movl    $.LC0, %edi
    addq    $8, %rsp
    jmp    puts
    .cfi_endproc
.LFE12:
    .size    whileloop, .-whileloop
    .p2align 4,,15
.globl forloop
    .type    forloop, @function
forloop:
.LFB11:
    .cfi_startproc
    subq    $8, %rsp
    .cfi_def_cfa_offset 16
    movl    $.LC0, %edi
    call    puts
    movl    $.LC0, %edi
    call    puts
    movl    $.LC0, %edi
    call    puts
    movl    $.LC0, %edi
    addq    $8, %rsp
    jmp    puts
    .cfi_endproc
.LFE11:
    .size    forloop, .-forloop
    .p2align 4,,15
.globl main
    .type    main, @function
main:
.LFB13:
    .cfi_startproc
    subq    $8, %rsp
    .cfi_def_cfa_offset 16
    movl    $.LC0, %edi
    call    puts
    movl    $.LC0, %edi
    call    puts
    movl    $.LC0, %edi
    call    puts
    movl    $.LC0, %edi
    call    puts
    movl    $.LC0, %edi
    call    puts
    movl    $.LC0, %edi
    call    puts
    movl    $.LC0, %edi
    call    puts
    movl    $.LC0, %edi
    addq    $8, %rsp
    jmp    puts
    .cfi_endproc
.LFE13:
    .size    main, .-main
    .ident    "GCC: (Debian 4.4.5-8) 4.4.5"
    .section    .note.GNU-stack,"",@progbits



As you can see with O3 the compiler is smart enough to optimize both loops to not even do a loop or any jumps and just does 4 prints and then in the main method it just does 8 prints instead of even using call on those two methods.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List