Author: David Rasmussen
Date: 08:09:58 01/23/02
Go up one level in this thread
On January 22, 2002 at 21:07:57, Russell Reagan wrote:
>I'm just analyzing a few loops and originally I was using C++ and iostream's
>cout for displaying the result. I wondered if compiling the same thing in C and
>using printf would make any difference...it did. Before I could hardly read the
>ASM because it was strung out with all kinds of garbage. The ASM/source file
>generated using C was 2K, the C++ one was 440K. Go figure, all for this:
>
>#include <stdio.h>
>
>void main() {
>
> char squares[64];
> int i;
> int found = 0;
>
> for(i = 0; i < 64; i++) {
>
> if(squares[i] == 1)
> found = 1;
>
> }
>
> printf("%d",found);
>
>}
>
>You think there might be a little hidden overhead in C++?!
>
>Russell
Probably because printf is a macro, and using cout force you to link the entire
class or even the entire library into the file. If you were using a shared
library (on Linux, for example) this wouldn't happen. Anyway, it doesn't matter
for real programs other than Hello World type programs. I use C++ I/O and my
executable is not big, and most importantly, it isn't slower at all than C I/O.
On the other hand, it is often faster.
/David
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.