size of executable file?

Discussion of programming on Linux, including shell scripting, perl, python, c/c++, mono, java. Whatever tickles your fancy.
Post Reply
khan001
Cadet
Posts: 3
Joined: Sat Feb 05, 2011 10:56 pm

size of executable file?

Post by khan001 »

salam everyone.
i am new user in linux . i didnt know much about about linux. iwant to use linux for programming .i have knowledge about C language.

int myarray[50000]={1,2,3,4};
int main(void){
myarray[0]=3;
return 0;
}
_______________

int myarray[50000];
int main(void){
myarray[0]=3;
return 0;
}


i want to check the SIZE OF EXECUTABLE files of above code?please tell me what is the size of above files...and how can i check the size?
lambda
Major General
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Location: Lahore
Contact:

Post by lambda »

this should answer your question:

Code: Select all

$ cat a.c; cc -o a a.c; ls -l a; size a
int myarray[50000] = {1,2,3,4}; 
int main(void)
{
        myarray[0]=3; 
        return 0; 
} 
-rwxr-xr-x 1 me me 208483 2011-02-07 14:08 a
   text    data     bss     dec     hex filename
   1068  200528      16  201612   3138c a
$ 
$ cat b.c; cc -o b b.c; ls -l b; size b
int myarray[50000]; 
int main(void)
{ 
        myarray[0]=3; 
        return 0; 
} 
-rwxr-xr-x 1 me me 8443 2011-02-07 14:08 b
   text    data     bss     dec     hex filename
   1068     512  200032  201612   3138c b
$ 
but perhaps you care about only the code you've written, and none of the rest (libc-related code). in that case, just look at the object size:

Code: Select all

$ cat a.c; cc -c -o a.o a.c; ls -l a.o; size a.o
int myarray[50000] = {1,2,3,4}; 
int main(void)
{
        myarray[0]=3; 
        return 0; 
} 
-rw-r--r-- 1 me me 201368 2011-02-07 14:10 a.o
   text    data     bss     dec     hex filename
     77  200000       0  200077   30d8d a.o
$ cat b.c; cc -c -o b.o b.c; ls -l b.o; size b.o
int myarray[50000]; 
int main(void)
{ 
        myarray[0]=3; 
        return 0; 
} 
-rw-r--r-- 1 me me 1360 2011-02-07 14:10 b.o
   text    data     bss     dec     hex filename
     77       0       0      77      4d b.o
$ 
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
Post Reply