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

C arrays

Name: Anonymous 2008-11-15 10:18

is there a way to do this all in one function instead of splitting it into two?
#include <stdlib.h>

void stuff_with_a(char a[20000000][20]){
 for(int i = 0; i < 20000000; ++i){
  for(int j = 0; j < 20; ++j)
   a[i][j] = 0;
 }
}

int main(){
 char *a = malloc(20000000*20);
 stuff_with_a(a);
 sleep(60);
 return 0;
}

Name: Anonymous 2008-11-16 18:50

>>19
given the code in >>1, gcc produces:
        .file   "test.c"
        .text
.globl stuff_with_a
        .type   stuff_with_a, @function
stuff_with_a:
        pushl   %ebp
        xorl    %ecx, %ecx
        movl    %esp, %ebp
        movl    8(%ebp), %edx
        jmp     .L2
.L3:
        movb    $0, -1(%eax,%edx)
        incl    %eax
        cmpl    $21, %eax
        jne     .L3
        incl    %ecx
        addl    $20, %edx
        cmpl    $20000000, %ecx
        je      .L6
.L2:
        movl    $1, %eax
        jmp     .L3
.L6:
        popl    %ebp
        ret
        .size   stuff_with_a, .-stuff_with_a
.globl main
        .type   main, @function
main:
        leal    4(%esp), %ecx
        andl    $-16, %esp
        pushl   -4(%ecx)
        pushl   %ebp
        movl    %esp, %ebp
        pushl   %ecx
        subl    $16, %esp
        pushl   $400000000
        call    malloc
        pushl   %eax
        call    stuff_with_a
        popl    %eax
        popl    %edx
        pushl   $60
        call    sleep
        movl    -4(%ebp), %ecx
        xorl    %eax, %eax
        leave
        leal    -4(%ecx), %esp
        ret
        .size   main, .-main
        .ident  "GCC: (GNU) 4.2.1 20070719  [FreeBSD]"

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