a namespace/header file question?

Hi
I have:
Version 1
1
2
3
4
5
#include <iostream>
using namespace std;
int main(){
	cout << "Hello World!" << endl;
}


Version 2
1
2
3
4
#include <iostream>
int main(){
	std::cout << "Hello World!" << std::endl;
}


Naturally the two executables have the same size (7.7KB).

Is there a way to reduce the executable size assuming that i'm only using cout and endl?!
Thanks
Huh? No. 7K is about as small as you will get if you want to do input/output.
What do you need something that small for, anyway?
Just curious :)
strip -s -x the executable reduced the size from 6778 bytes to 4256 on my pc.
You could also check your compiler's available options for size optimization. I'm not so sure it's going to make much difference with something this small, though.
Last edited on
You were right about the strip ...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ g++ -Wall v2.cpp -o final
$ ls -l
total 12
-rwxr-xr-x 1 torrao torrao 7930 Dez  9 22:01 final
-rw-r--r-- 1 torrao torrao   88 Dez  9 21:58 v2.cpp
$ strip final
$ ls -l
total 8
-rwxr-xr-x 1 torrao torrao 4048 Dez  9 22:02 final
-rw-r--r-- 1 torrao torrao   88 Dez  9 21:58 v2.cpp
$ strip -R.comment final 
$ ls -l
total 8
-rwxr-xr-x 1 torrao torrao 3796 Dez  9 22:02 final
-rw-r--r-- 1 torrao torrao   88 Dez  9 21:58 v2.cpp 


I went from 7930 to 3796, wish represents about 48% of the initial size.
And looks like there is more in this post: http://utilitybase.com/article/show/2007/04/09/225/Size+does+matter:+Optimizing+with+size+in+mind+with+GCC

Still get the "Hello World!" :)
Topic archived. No new replies allowed.