While reading from a site a read that you can not make a global variable of type register.Why is it so?
source:
http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=/com.ibm.xlcpp8l.doc/language/ref/regdef.htm
While reading from a site a read that you can not make a global
Share
In theory, you could allocate a processor register to a global scope variable – that register would simply have to remain allocated to that variable for the whole life of the program.
However, C compilers don’t generally get to see the entire program during the compile phase – the C standard was written so that each translation unit (roughly corresponding to each
.cfile) could be compiled independently of the others (with the compiled objects later linked into a program). This is why global scope register variables aren’t allowed – when the compiler is compilingb.c, it has no way to know that there was a global variable allocated to a register ina.c(and that therefore functions inb.cmust preserve the value in that register).