Bonsoir tous ,
combien d'octets contient le type TCHAR ?
Version imprimable
Bonsoir tous ,
combien d'octets contient le type TCHAR ?
Bonjour,
tout dépend du character set utilisé (sous Visual studio, voire Project -> Properties -> Configuration Properties -> general -> Character Set) qui est soit en MBCS (MultiByte character set) ou Unicode.
En MBCS, TCHAR est un typedef sur le type char:
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 // extrait de <tchar.h> #ifdef _MBCS /* ++++++++++++++++++++ MBCS ++++++++++++++++++++ */ // [snip] #ifndef _TCHAR_DEFINED #if !__STDC__ typedef char TCHAR; #endif #define _TCHAR_DEFINED #endif //[...]
En Unicode, c'est un typedef sur wchar_t :
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 #ifdef _UNICODE /* ++++++++++++++++++++ UNICODE ++++++++++++++++++++ */ // [snip] #ifndef _TCHAR_DEFINED #if !__STDC__ typedef wchar_t TCHAR; #endif #define _TCHAR_DEFINED #endif // [...]
Un simple sizeof suffit à déterminer la taille (qui est dépendante de l'implémentation, pas de la spécification):
Code:
1
2
3
4
5
6
7
8 #include <iostream> int _tmain(void) { std::cout << "Sizeof(TCHAR): " << sizeof(TCHAR) << std::endl; return 0; }
Output :
Citation:
x86 - Unicode: sizeof(TCHAR): 2
x64 - Unicode: sizeof(TCHAR): 2
x86 - MBCS : sizeof(TCHAR): 1
x64 - MBCS: sizeof(TCHAR): 1