GCC 4.1.2: Character array initialization issue

Vardhan, Sundara (GE Infra, Energy) sundara.vardhan@ge.com
Tue Feb 2 17:56:00 GMT 2010


Hi All-

I am using GCC 4.1.2 in Linux 5.4 RHEL. I see the following issue. Any
pointers or advice will be greatly appreciated.

typedef char big_at[1000000];
int main()
{
char    big_a[1000000] = "";
big_at  big_b = "";
return(0);
}

The result is:

>cc *.c; ls -l
-rwxrwxr-x 1 bondcl xa 1006752 Feb  2 10:13 a.out
-rw-rw-r-- 1 bondcl xa     104 Feb  2 10:13 test.c

Note the size of the resulting a.out file. An alternate:

typedef char big_at[1000000];
int main()
{
char    big_a[1000000] = {'\0'};
big_at  big_b = {'\0'};
return(0);
}

Results in:

>cc *.c; ls -l
-rwxrwxr-x 1 bondcl xa 6736 Feb  2 10:09 a.out
-rw-rw-r-- 1 bondcl xa  112 Feb  2 10:09 test.c

Why is the difference in the size of the a.out file. Am I missing any
compiler option?

With Regards

Vardhan



More information about the Gcc-help mailing list