views:

71

answers:

3

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!

A: 

You can use qint64 from Qt framework(Platform independent), but probably there are easier ways.

metdos
+1  A: 

For the 64-bit:

typedef long long __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.

Goz
This seems like a really good solution, thanks!
shuttle87
A: 

GCC supports long long (depending on compilation flags), which is a 64-it integer. Or you can use std::int64_t from the cstdint header.

Or to be more cross-platform, use boost/cstdint.hpp, which defines boost::int64_t

_tmain is just Microsoft being silly (or nonstandard, if you will) The rest of the world uses main, plain and simple. _TCHAR has no direct equivalent, but since you say you don't need to support wchar_t, you can just replace it wit char.

jalf
Why the downvote?
jalf