Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Porting windows code, what to use instead of __int64 _tmain and _TCHAR*?

I'm currently porting some windows code and trying to make it available for use in Ubuntu. The project was originally compiled in VC++ without any issues. Also I should note that this only needs to work in Ubuntu, but more platform independent ideas are certainly welcome.

Most of the code is easy to port as it is mostly a numerical simulation project with few OS specific parts. There is no UNICODE used in the ported version and there is not going to be any need to support this.

I'd like to know what the best practices are when trying to get this code to compile with GCC, in particular:

What is considered to be the best replacement for: __int64, _tmain and _TCHAR* ?

Thanks!

like image 767
shuttle87 Avatar asked Jun 24 '10 08:06

shuttle87


1 Answers

For the 64-bit:

#include <inttypes.h>
typedef int64_t __int64;

As for the TCHAR problem. I actually find TCHARs rather useful so I have a file with all the _t functions I use in it.

e.g

#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

as for the _s functions basically ... I implemented them. It takes about an hour of coding to do but it makes porting projects to other platforms or compilers IMMENSELY easier.

like image 149
Goz Avatar answered Oct 04 '22 17:10

Goz