[英]32-bit C++ to 64-bit C++ using Visual Studio 2010
I recently want to convert a 32-bit C++ project to 64-bit, but I am stuck with the first try. 最近,我想将32位C ++项目转换为64位,但是我坚持第一次尝试。 Could you point out any suggestions/checklist/points when converting 32-bit C++ to 64-bit in VS (like converting 32-bit Delphi to 64-bit). 在VS中将32位C ++转换为64位时(例如将32位Delphi转换为64位),您能指出任何建议/清单吗?
int GetVendorID_0(char *pVendorID,int iLen)
{
#ifdef WIN64 // why WIN64 is not defined switching to Active (x64) ?
// what to put here?
#else
DWORD dwA,dwB,dwC,dwD;
__asm
{
PUSHAD
MOV EAX,0
CPUID //CPUID(EAX=0),
MOV dwA,EAX
MOV dwC,ECX
MOV dwD,EDX
MOV dwB,EBX
POPAD
}
memset( pVendorID, 0,iLen);
memcpy( pVendorID, &dwB,4);
memcpy(&pVendorID[4], &dwD,4);
memcpy(&pVendorID[8], &dwC,4);
return dwA;
#endif
}
Microsoft's compilers (some of them, anyway) have a flag to point out at least some common problems where code will probably need modification to work as 64-bit code. Microsoft的编译器(无论如何还是其中的一些)都有一个标志,指出至少一些常见的问题,其中的代码可能需要修改才能用作64位代码。
As far as your GetVendorID_0
function goes, I'd use Microsoft's _cpuid
function, something like this: 就您的GetVendorID_0
函数而言,我将使用Microsoft的_cpuid
函数,如下所示:
int GetVendorID_0(char *pVendorID, int iLen) {
DWORD data[4];
_cpuid(0, data);
memcpy(pVendorID, data+1, 12);
return data[0];
}
That obviously doesn't replace all instances of inline assembly language. 显然,这并不能取代内联汇编语言的所有实例。 You choices are fairly simple (though not necessarily easy). 您的选择相当简单(尽管不一定很容易)。 One is to find an intrinsic like this to do the job. 一种是找到这样的内在要素来完成这项工作。 The other is to move the assembly code into a separate file and link it with your code in C++ (and learn the x64 calling convention). 另一种是将汇编代码移动到一个单独的文件中,并将其与C ++中的代码链接(并学习x64调用约定)。 The third is to simply forego what you're doing now, and write the closest equivalent you can with more portable code. 第三是简单地放弃您现在正在做的事情,并使用可移植的代码编写与您最接近的等价物。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.