OTOH, I think this goes toward the myth that OO is somehow
>inherently more wasteful of resources than other techniques.
It's not OO I was talking about, but C++ specifically.
As a totally non-scientific example, write a hello world program in C. Compare the binary sizes when compiling with C and C++, even with exceptions turned off. C++ compilers are still catching up in the efficiency department.
--
"Jokes mentioning ducks were considered particularly funny." - cnn.com
"Hello world" is probably not the best test of a compiler, since were mostly using libraries, but I'll bite.
I compile the following program natively using GCC 3.2.2 under Redhat Linux.
main.c:
#include
int main(int argc,char* argv[]){ printf("Hello world.\n"); }
% gcc -fno-exceptions -fno-rtti -o main -x c main.c % strip main
-rwxrwxrwx 1 mike mike 2788 Apr 30 17:28 main
% gcc -fno-exceptions -fno-rtti -o main -x c main.c % strip main
-rwxrwxrwx 1 mike mike 2792 Apr 30 17:27 main
The C++ program is 4 bytes larger.
BTW, I got the same results with exceptions and rtti enabled.
While we're at it, here is the result of a few other GCC cross compilers.
xscale-elf-gcc -fno-exceptions -fno-rtti -c -x c main.c xscale-elf-strip main.o
-rw-rw-rw- 1 mike mike 500 Apr 30 17:49 main.o
xscale-elf-gcc -fno-exceptions -fno-rtti -c -x c++ main.c xscale-elf-strip main.o
-rw-rw-rw- 1 mike mike 508 Apr 30 17:50 main.o
powerpc-eabi-gcc -fno-exceptions -fno-rtti -c -x c main.c powerpc-eabi-strip main.o
-rw-rw-rw- 1 mike mike 532 Apr 30 17:52 main.o
powerpc-eabi-gcc -fno-exceptions -fno-rtti -c -x c++ main.c powerpc-eabi-strip main.o
-rw-rw-rw- 1 mike mike 536 Apr 30 17:51 main.o
h8300-elf-gcc -fno-exceptions -fno-rtti -c -x c main.c h8300-elf-strip main.o
-rw-rw-rw- 1 mike mike 428 Apr 30 17:54 main.o
h8300-elf-gcc -fno-exceptions -fno-rtti -c -x c++ main.c h8300-elf-strip main.o
-rw-rw-rw- 1 mike mike 428 Apr 30 17:54 main.o
Again, this is a bad and quite way to compare languages, but ...
To paraphrase someone whose name escapes me, "First make it right, then optimize."
--
Michael N. Moran (h) 770 516 7918
5009 Old Field Ct. (c) 678 521 5460
Kennesaw, GA, USA 30144 http://mnmoran.org
"... abstractions save us time working, but they don't
save us time learning."
Joel Spolsky, The Law of Leaky Abstractions
The Beatles were wrong: 1 & 1 & 1 is 1
Only 100 more bytes in C++, but virtually all of that is from the startup code it is linked to. When compiling to an assembly I can see that the C++ version has merely one extra move instruction so that main() returns a valid value.
--
Darin Johnson
Where am I? In the village... What do you want? Information...
- a book no embedded software developer should be without.
-- Guy Macon, Electronics Engineer & Project Manager for hire. Remember Doc Brown from the _Back to the Future_ movies? Do you have an "impossible" engineering project that only someone like Doc Brown can solve? My resume is at
Along with Kernighan & Pike's "The Practice of Programming", Brooks' "The Mythical Man Month", and Bignell and Fortune's "Understanding Systems Failures".
pete
--
pete@fenelon.com "there's no room for enigmas in built-up areas"
gcc -static -fno-exceptions -fno-rtti -x c++ -o main main.c strip main ls -l main
-rwxrwxrwx 1 mike mike 377888 May 1 07:53 main
gcc -static -fno-exceptions -fno-rtti -x c -o main main.c strip main ls -l main
-rwxrwxrwx 1 mike mike 377888 May 1 07:54 main
--
Michael N. Moran (h) 770 516 7918
5009 Old Field Ct. (c) 678 521 5460
Kennesaw, GA, USA 30144 http://mnmoran.org
"... abstractions save us time working, but they don't
save us time learning."
Joel Spolsky, The Law of Leaky Abstractions
The Beatles were wrong: 1 & 1 & 1 is 1
You forgot the -fno-exceptions -fno-rtti switches. My results have identical sizes with those.
gcc -static -fno-exceptions -fno-rtti -x c -o main main.c strip main ls -l main
-rwxrwxrwx 1 mike mike 377888 May 1 07:54 main
gcc --static -fno-exceptions -fno-rtti -x c++ -o main main.c strip main ls -l main
-rwxrwxrwx 1 mike mike 377888 May 1 07:56 main
--
Michael N. Moran (h) 770 516 7918
5009 Old Field Ct. (c) 678 521 5460
Kennesaw, GA, USA 30144 http://mnmoran.org
"... abstractions save us time working, but they don't
save us time learning."
Joel Spolsky, The Law of Leaky Abstractions
The Beatles were wrong: 1 & 1 & 1 is 1
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.