what if the compiler doesnt know ??
If you mean those 2 diff. variables of same type.
The below is going to take somewhat less cycyle in some cases
But how much less is going to depend upon some other factors & implementation details
Like what kind of variable? Whether compiler decide to store local variable in CPU register or not? How the C++ class structure implemented by compiler?
Here code generated by VC compiler.
It generating following code for local variable
Code:
00411AEA mov eax,dword ptr [CPY]
00411AED push eax
& Its generating below code for class member access
Code:
00411AFB mov eax,dword ptr [this]
00411AFE mov ecx,dword ptr [eax]
00411B00 push ecx
Note its doing one extra move to get first member
Some aggressive optimized compiler might give you same cycles for both
Vinod