C++ 移植windows代码,使用什么来代替uu int64 tmain和TCHAR*?
我目前正在移植一些windows代码,并试图将其用于Ubuntu。该项目最初是在VC++中编译的,没有任何问题。我还应该注意到,这只需要在Ubuntu中工作,但更多平台无关的想法当然是受欢迎的 大多数代码都很容易移植,因为它主要是一个数值模拟项目,很少有特定于操作系统的部分。移植版本中没有使用UNICODE,也不需要支持这一点 我想知道在试图使用GCC编译此代码时的最佳实践是什么,特别是: 什么被认为是最好的替代品:u_int64、_tmain和_TCHAR* 谢谢 您可以使用Qt框架(独立于平台),但可能有更简单的方法。对于64位:C++ 移植windows代码,使用什么来代替uu int64 tmain和TCHAR*?,c++,windows,gcc,porting,C++,Windows,Gcc,Porting,我目前正在移植一些windows代码,并试图将其用于Ubuntu。该项目最初是在VC++中编译的,没有任何问题。我还应该注意到,这只需要在Ubuntu中工作,但更多平台无关的想法当然是受欢迎的 大多数代码都很容易移植,因为它主要是一个数值模拟项目,很少有特定于操作系统的部分。移植版本中没有使用UNICODE,也不需要支持这一点 我想知道在试图使用GCC编译此代码时的最佳实践是什么,特别是: 什么被认为是最好的替代品:u_int64、_tmain和_TCHAR* 谢谢 您可以使用Qt框架(独立于平
#include <inttypes.h>
typedef int64_t __int64;
至于_s函数基本上。。。我实现了它们。编写代码大约需要一个小时,但这使得将项目移植到其他平台或编译器变得非常容易。GCC支持
long
(取决于编译标志),这是一个64位的整数。也可以从cstdint
标题使用std::int64_t
或者更跨平台,使用定义了boost::int64\t
\u tmain
仅仅是微软的愚蠢(或者不标准,如果你愿意的话)世界其他地方使用的main
,简单明了。
\u TCHAR
没有直接的等价物,但是既然你说你不需要支持wchar\u t
,你可以用char
替换它,这不是很愚蠢,而是历史\u tmain()
是微软在没有主要操作系统支持Unicode的情况下决定使用Unicode的UCS-2的结果。UCS-2基于16位字符单元,因此main()
需要一个“宽字符”/Unicode对应项,\u tmain()
被解析为main()
或基于是否编译Unicode构建的16位字符等效项。后来,其他操作系统采用了基于8位字符单位的UTF-8版本,因此仍然可以使用main()
,而Windows则从UCS-2改为基于16位字符单位的UTF-16。
#ifdef UNICODE
#define _tcslen wcslen
#define _tcscpy wcscpy
#define _tcscpy_s wcscpy_s
#define _tcsncpy wcsncpy
#define _tcsncpy_s wcsncpy_s
#define _tcscat wcscat
#define _tcscat_s wcscat_s
#define _tcsupr wcsupr
#define _tcsupr_s wcsupr_s
#define _tcslwr wcslwr
#define _tcslwr_s wcslwr_s
#define _stprintf_s swprintf_s
#define _stprintf swprintf
#define _tprintf wprintf
#define _vstprintf_s vswprintf_s
#define _vstprintf vswprintf
#define _tscanf wscanf
#define TCHAR wchar_t
#else
#define _tcslen strlen
#define _tcscpy strcpy
#define _tcscpy_s strcpy_s
#define _tcsncpy strncpy
#define _tcsncpy_s strncpy_s
#define _tcscat strcat
#define _tcscat_s strcat_s
#define _tcsupr strupr
#define _tcsupr_s strupr_s
#define _tcslwr strlwr
#define _tcslwr_s strlwr_s
#define _stprintf_s sprintf_s
#define _stprintf sprintf
#define _tprintf printf
#define _vstprintf_s vsprintf_s
#define _vstprintf vsprintf
#define _tscanf scanf
#define TCHAR char
#endif