Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Why doesn't this end

Name: Anonymous 2010-10-31 5:35

#include <stdio.h>

main()
{

    int a;

while(a != 256)
    {putchar(a);
    a++;}
}

But if I add  a = 0;  after int a;, it ends fine?

Something to do with a variable not being initialized properly, and therefore, not being able to be compared or something?

Compiled with Code::Blocks+GCC or mingw or something. The debugger also reports no relevant issues with the initial code.

Name: >>3 2010-10-31 9:29

>>33
It doesn't really take that long to run it, here's a quick benchmark I just wrote:

RDTSC
XOR ECX,ECX

LOOP:        
INC ECX
JNZ SHORT LOOP
MOV ECX,EAX
MOV EBX,EDX
RDTSC
SUB EAX,ECX
SUB EDX,EBX

This results is: eax = 019E6C7A, edx= 00000001 here, which is only some 1-2s on my x86 CPU.

For those that can't read x86 asm, that's the equivalent of:

unsigned int i = 0; while(++i);

With some timing code wrapped around at the start and end (well, actually it's a tick count, however given the processor and its frequency, you can convert it into a time unit).

Name: Anonymous 2010-10-31 9:31

>>34
There is a bottleneck, and it is putchar.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List