7,765
社区成员
发帖
与我相关
我的任务
分享
namespace test
{
using System;
class Program
{
static void Main(string[] args)
{
int a, b;
a = 100;
b = 3;
b = a + 0 * (a = b);
Console.WriteLine(a + "," + b);
}
}
}
//000011: b = a + 0 * (a = b);
IL_0005: ldloc.0
IL_0006: ldloc.1
IL_0007: stloc.0
IL_0008: stloc.1
b = a + 0 * (a = b);
0000002f mov eax,dword ptr [ebp-8]
00000032 mov dword ptr [ebp-10h],eax
00000035 mov eax,dword ptr [ebp-0Ch]
00000038 mov dword ptr [ebp-8],eax
0000003b mov eax,dword ptr [ebp-10h]
0000003e mov dword ptr [ebp-0Ch],eax
mov eax,1
mov ebx,2
push eax
push ebx
pop eax
pop ebx
#include <stdio.h>
#define SWAP(a,b) do ((&(a))!=(&(b)))?((a)^=(b)^=(a)^=(b)):((a)=(a)); while (0)
char *p1="1" ,*p2="2" ;
char c1=1 , c2=2 ;
short s1=1 , s2=2 ;
int i1=1 , i2=2 ;
__int64 I1=1i64, I2=2i64;
float f1=1.0f, f2=2.0f;
double d1=1.0 , d2=2.0 ;
void main() {
SWAP((int)p1,(int)p2); printf("char * %5s, %5s\n",p1,p2);
SWAP(c1,c2); printf("char %5d, %5d\n",c1,c2);
SWAP(s1,s2); printf("short %5d, %5d\n",s1,s2);
SWAP(i1,i2); printf("int %5d, %5d\n",i1,i2);
SWAP(I1,I2); printf("__int64 %5I64d,%5I64d\n",I1,I2);
SWAP(*(int *)&f1,*(int *)&f2);printf("float %5g, %5g\n",f1,f2);
SWAP(*(__int64 *)&d1,*(__int64 *)&d2);printf("double %5lg, %5lg\n",d1,d2);
SWAP(c1,c1);
printf("%d\n",c1);
}
//char * 2, 1
//char 2, 1
//short 2, 1
//int 2, 1
//__int64 2, 1
//float 2, 1
//double 2, 1
//2