tchar.h on linux
Asked Answered
E

2

25

I am trying to write cross platform i18n C++ code. Since most linux system prefer to use UTF-8 as the character encoding, I thought that I should use string on linux and wstring on Windows. Is tchar.h available on linux? What is an equivalent replacement on for tchar.h on Linux?

Exine answered 21/5, 2009 at 23:37 Comment(0)
M
12

You may find this article to be useful. In particular, near the end they discuss a bit about using TCHAR and dealing with Windows code.

The article summarization is:

TCHAR will be translated into a wide character data type when compiling this code with the GNU C Compiler (most portable libraries define TCHAR in their headers and refer to wchar_t). This, in fact, was how I turned my C++ program into an anagram generator: I used standard C++ strings filled with UTF-8 and fed the data with pointers casted to wchar_t to library functions. UTF-8 data interpreted as UTF-32 equals garbage (but it is tremendously useful for obfuscation of data and bugs).

Michelmichelangelo answered 21/5, 2009 at 23:42 Comment(1)
To be clear, tchar.h is Windows only. But it's fairly trivial to roll your own tchar.h.Roofdeck
I
0

To build my Windows centric source I was able to use the tchar.h file from Cygwin's found in the cygwin\usr\include\w32api folder.

I am actually building using Android NDK. For my purposes I made a copy of tchar.h and patched it.

//#include <crtdefs.h>

#define _CRTIMP

//#define _strninc(_pc,_sz) (((_pc)+(_sz)))
//  _CRTIMP size_t __cdecl __strncnt(const char *_Str,size_t _Cnt);
Inna answered 29/3, 2017 at 16:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.