Please explain register getchar_unlocked()

Why is c=gc() is in the increment part of the for loop header? What exactly is it doing?
Also what is the register keyword?

1
2
3
4
5
6
7
8
  #define getchar_unlocked gc()
void scanint(int &x)
{
    register int c = gc();
    x = 0;
    for(;(c<48 || c>57);c = gc());
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
}
You have not provided the definition for gc() so we have no idea why this code is doing what it is doing.

register is a keyword from C - it's pointless though because the default is for local variables to be in the register. This code was probably written for an older compiler (like, very very old) that couldn't properly decide where to store variables.
The first line provides the definition for gc()
#define getchar_unlocked gc()

I've read that this kind of taking input is the fastest of all others and I guess it was written for modern compilers only.
No, that line defines getchar_unlocked as being a macro for gc(). It does not define gc().

Could you explain where you read that? I have a feeling you misread or that the source is incorrect.
Last edited on
Topic archived. No new replies allowed.