When I read this question, I remembered how someone once told me (many years ago) that from the point of view of assembler, these two operations are very different:
n = 0; n = n - n;
This is true, and if so, why is this so?
EDIT: As noted by some answers, I think it would be pretty easy for the compiler to optimize to the same thing. But what I find interesting is why they will be different if the compiler has a common approach.
. " ". :
move.l #0, d0 moveq.l #0, d0 sub.l a0,a0
op-, (0). , , ( ). Sloooow.
moveq.l , op-, 0 7 . , . , ( op-. Bad.).
, , , . C,
n = n - n;
n ( ).
n
, :
xor eax, eax
mov eax, 0
, . 1 ( 2). , - ( sub).
V++ 6.0 :
4: n = 0; 0040102F mov dword ptr [ebp-4],0 5: 6: n = n - n; 00401036 mov eax,dword ptr [ebp-4] 00401039 sub eax,dword ptr [ebp-4] 0040103C mov dword ptr [ebp-4],eax
.
, n volatile .
volatile
XORing , C.
C , , - .
..,
n=0 n=n-n
, n - , . http://www.codinghorror.com/blog/archives/001266.html
Source: https://habr.com/ru/post/1708404/More articles:Websphere Configuration Template - websphereIs RegEx safe from the user? - c #Problem with Facebook + django - djangoHQL: sort all elements by a specific element on their map - hibernateFreelance backup from timemachine capsule - amazon-s3Тенденции внешнего удостоверения личности из приложений - xacmlParse text from a batch file - command-linehttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1708407/is-a-versioning-system-or-code-repository-necessary-for-a-single-developer&usg=ALkJrhhPqCxMc5RPhQG7YjiMFkZqepU79AEasy editor for web.config files - web-configWorking with javascript in VIsual Studio - javascriptAll Articles