Why does gcc take a long time to compile a C code if it has a big array in the extern block?
#define MAXNITEMS   100000000
int buff[MAXNITEMS];
int main (int argc, char *argv[])
{
   return 0;
}
Why does gcc take a long time to compile a C code if it has a big array in the extern block?
#define MAXNITEMS   100000000
int buff[MAXNITEMS];
int main (int argc, char *argv[])
{
   return 0;
}
 
    
    I suspect a bug somewhere. There is no reason for the compile to take longer, no matter how big the array is since the compiler will just write an integer into the .bss segment since you never assign a value to an element in it. Proof:
        .file   "big.c"
        .comm   buff,4000000000000000000,32
        .text
        .globl  main
        .type   main, @function
main:
.LFB0:
        .cfi_startproc
        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
        movq    %rsp, %rbp
        .cfi_def_cfa_register 6
        movl    %edi, -4(%rbp)
        movq    %rsi, -16(%rbp)
        movl    $0, %eax
        popq    %rbp
        .cfi_def_cfa 7, 8
        ret
        .cfi_endproc
.LFE0:
        .size   main, .-main
        .ident  "GCC: (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3"
        .section        .note.GNU-stack,"",@progbits
As you can see, the only thing left of the array in the assembly is .comm   buff,4000000000000000000,32.
I suggest you gcc with -S to see the assembler code. Maybe your version of GCC has bug. I tested with GCC 4.7.3 and the compile times here are the same, no matter which value I use.
 
    
    