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 0:54

>>14
Given the input file, test.c:
void func( int a[9001] ) {
    a[0] = 1;
}


gcc -S produces the following --
    .file    "test.c"
    .text
    .p2align 4,,15
.globl func
    .type    func, @function
func:
    pushl    %ebp
    movl    %esp, %ebp
    movl    8(%ebp), %eax
    movl    $1, (%eax)
    popl    %ebp
    ret
    .size    func, .-func
    .ident    "GCC: (GNU) 4.2.1 20070719  [FreeBSD]"

tl;dr it's passing by-reference, as I thought it did. No bricks have been shat.

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