CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//Register is a request to compiler to treat a variable storage in CPU register.
//C++11 has depricated this usage as it was just a request
//and now standard itself manages the same implementation on its own
//It does not allow to take address of register variable. Don't know why Sololearn allows it
//also check that global variable with register storage is not allowed correctly on Sololearn as well
//Reason of not allowing global object as register:
/*
In C, a global variable has to be reachable from any separately compiled file. If you make it a register variable, that would have to be known to every file that could access it and would require that a specific register be locked down for that purpose.
For a local variable, locking down a variable in a register only makes the job of the compiler slightly difficult. Even so, the language standard does not require a register variable to held in a register, though it does not permit you to treat it as if it has a memory address (e.g., using operator &).
*/
#include <iostream>
using namespace std;
void* operator new(size_t t)
{
cout << "bytes " << t << endl;
return malloc(t);
}
struct test
{
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run