gpt4 book ai didi

c++ - 移植 windows 代码,用什么代替 __int64 _tmain 和 _TCHAR*?

转载 作者:可可西里 更新时间:2023-11-01 12:45:01 25 4
gpt4 key购买 nike

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

大部分代码很容易移植,因为它主要是一个数值模拟项目,只有很少的操作系统特定部分。移植版本中没有使用 UNICODE,也不需要支持它。

我想知道当试图让这段代码用 GCC 编译时最佳实践是什么,特别是:

什么被认为是 __int64、_tmain 和 _TCHAR* 的最佳替代品?

谢谢!

最佳答案

对于 64 位:

#include <inttypes.h>
typedef int64_t __int64;

至于TCHAR问题。我实际上发现 TCHAR 相当有用,所以我有一个文件,其中包含我在其中使用的所有 _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 功能基本上......我实现了它们。这需要大约一个小时的编码时间,但它使将项目移植到其他平台或编译器变得非常容易。

关于c++ - 移植 windows 代码,用什么代替 __int64 _tmain 和 _TCHAR*?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3108220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com