移植Windows代码,使用什么而不是__int64 _tmain和_TCHAR *?

我目前正在移植一些Windows代码,并试图使其可用于Ubuntu中。 该项目最初是用VC ++编译的,没有任何问题。 另外我应该注意的是,这只需要在Ubuntu中工作,但更多的平台独立的想法当然是受欢迎的。

大多数代码很容易移植,因为它大部分是一个数字模拟项目,只有很less的操作系统特定的部分。 在移植的版本中没有使用UNICODE,并且不需要任何支持。

我想知道当试图使用GCC编译代码时最佳做法是什么,特别是:

什么被认为是最好的替代:__int64,_tmain和_TCHAR *?

谢谢!

对于64位:

#include <inttypes.h> typedef int64_t __int64; 

至于TCHAR问题。 实际上我发现TCHARs非常有用,所以我有一个包含所有我在其中使用的_t函数的文件。

例如

 #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 

至于_s功能基本上…我执行它们。 这需要大约一个小时的编码才能完成,但它使得将项目移植到其他平台或编译器变得更加简单。

GCC支持long long (取决于编译标志),它是一个64整数的整数。 或者你可以使用cstdint标题中的std::int64_t

或者为了更跨平台,使用boost/cstdint.hpp ,它定义了boost::int64_t

_tmain只是微软愚蠢的(或者非标准的,如果你愿意)世界其他地方使用main ,简单的和简单的。 _TCHAR没有直接的等价物,但既然你说你不需要支持wchar_t ,你可以用char替换它。

你可以使用Qt框架中的qint64 (独立于平台),但可能有更简单的方法。