473,396 Members | 1,970 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

sizeof(TCHAR)

On my PC (running Windows) if I ask for sizeof(TCHAR) I get 1 if UNICODE
defined. Same if UNICODE (and _UNICODE) not defined. I sort of assumed
that under UNICODE it would be 2? I understand on UNIX it is often 4.

How can it be 1 for both ASCII AND Unicode?

Confused
Jul 20 '07 #1
6 13933
On Jul 20, 11:12 pm, "Angus" <nos...@gmail.comwrote:
On my PC (running Windows) if I ask for sizeof(TCHAR) I get 1 if UNICODE
defined. Same if UNICODE (and _UNICODE) not defined. I sort of assumed
that under UNICODE it would be 2? I understand on UNIX it is often 4.

How can it be 1 for both ASCII AND Unicode?

Confused
1. TCHAR is not a fundamental type according to the C++ standard. It
might be a type defined by your compiler.

2. sizeof(char) == 1 by definition. For other fundamental types, what
sizeof() returns is implementation defined.

-N

Jul 20 '07 #2
Neelesh Bodas wrote:
:: On Jul 20, 11:12 pm, "Angus" <nos...@gmail.comwrote:
::: On my PC (running Windows) if I ask for sizeof(TCHAR) I get 1 if
::: UNICODE defined. Same if UNICODE (and _UNICODE) not defined. I
::: sort of assumed that under UNICODE it would be 2? I understand
::: on UNIX it is often 4.
:::
::: How can it be 1 for both ASCII AND Unicode?
:::
::: Confused
::
:: 1. TCHAR is not a fundamental type according to the C++ standard.
:: It might be a type defined by your compiler.
::
:: 2. sizeof(char) == 1 by definition. For other fundamental types,
:: what sizeof() returns is implementation defined.
::

True. On a very popular Windows compiler, UNICODE and _UNICODE should
either both be defined, or both be undefined. Otherwise these
confusing things happen.

On the other hand, if you are coding for any currently supported
versions of Windows, you can just use wchar_t as the native character
type, and skip all this T-stuff.
Bo Persson
Jul 20 '07 #3

"Bo Persson" <bo*@gmb.dkwrote in message
news:5g*************@mid.individual.net...
Neelesh Bodas wrote:

True. On a very popular Windows compiler, UNICODE and _UNICODE should
either both be defined, or both be undefined. Otherwise these
confusing things happen.

On the other hand, if you are coding for any currently supported
versions of Windows, you can just use wchar_t as the native character
type, and skip all this T-stuff.
Bo Persson

I had the Unicode defines in the wrong file. With unicode defined,
sizeof(TCHAR) is 2

There are still Windows users running unsupported platforms so can't really
use wchar_t exclusively yet. One day.
Jul 21 '07 #4
On Jul 20, 8:12 pm, "Angus" <nos...@gmail.comwrote:
On my PC (running Windows) if I ask for sizeof(TCHAR) I get 1 if UNICODE
defined. Same if UNICODE (and _UNICODE) not defined. I sort of assumed
that under UNICODE it would be 2? I understand on UNIX it is often 4.
It depends on how you've defined it. It's easy to imagine
definitions where sizeof(TCODE) won't even compile.

In a C++ standards conformant mode, of course, the symbol cannot
be predefined. In some non-conformant modes, who knows, but
I've never heard of a Unix compiler predefining it in any mode.

--
James Kanze (Gabi Software) email: ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 22 '07 #5
On Jul 20, 9:21 pm, "Bo Persson" <b...@gmb.dkwrote:
Neelesh Bodas wrote:
:: On Jul 20, 11:12 pm, "Angus" <nos...@gmail.comwrote:
::: On my PC (running Windows) if I ask for sizeof(TCHAR) I get 1 if
::: UNICODE defined. Same if UNICODE (and _UNICODE) not defined. I
::: sort of assumed that under UNICODE it would be 2? I understand
::: on UNIX it is often 4.
::: How can it be 1 for both ASCII AND Unicode?
:: 1. TCHAR is not a fundamental type according to the C++ standard.
:: It might be a type defined by your compiler.
:: 2. sizeof(char) == 1 by definition. For other fundamental types,
:: what sizeof() returns is implementation defined.
True. On a very popular Windows compiler, UNICODE and _UNICODE should
either both be defined, or both be undefined. Otherwise these
confusing things happen.
On the other hand, if you are coding for any currently supported
versions of Windows, you can just use wchar_t as the native character
type, and skip all this T-stuff.
wchar_t is a C++ standard type, and available with any C++
compiler, regardless of the system. Just using wchar_t,
however, won't automatically make Unicode work anywhere. Using
wide characters is different from using char, no matter how you
cut it, and you need to adapt your program accordingly.

--
James Kanze (Gabi Software) email: ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 22 '07 #6
James Kanze wrote:
: On Jul 20, 9:21 pm, "Bo Persson" <b...@gmb.dkwrote:
:: Neelesh Bodas wrote:
:
:::: On Jul 20, 11:12 pm, "Angus" <nos...@gmail.comwrote:
::::: On my PC (running Windows) if I ask for sizeof(TCHAR) I get 1 if
::::: UNICODE defined. Same if UNICODE (and _UNICODE) not defined. I
::::: sort of assumed that under UNICODE it would be 2? I understand
::::: on UNIX it is often 4.
:
::::: How can it be 1 for both ASCII AND Unicode?
:
:::: 1. TCHAR is not a fundamental type according to the C++ standard.
:::: It might be a type defined by your compiler.
:
:::: 2. sizeof(char) == 1 by definition. For other fundamental types,
:::: what sizeof() returns is implementation defined.
:
:: True. On a very popular Windows compiler, UNICODE and _UNICODE
:: should either both be defined, or both be undefined. Otherwise
:: these confusing things happen.
:
:: On the other hand, if you are coding for any currently supported
:: versions of Windows, you can just use wchar_t as the native
:: character type, and skip all this T-stuff.
:
: wchar_t is a C++ standard type, and available with any C++
: compiler, regardless of the system. Just using wchar_t,
: however, won't automatically make Unicode work anywhere. Using
: wide characters is different from using char, no matter how you
: cut it, and you need to adapt your program accordingly.

Sure.

In this particular case, it's about using TCHAR that can be either a
char or a wchar_t in Windows headers. My point was that there is not
much use for an 8-bit char compile anymore, as all present Windows
versions use wchar_t natively anyway. So the OP might want to skip
tons of non-standard macros, and use whar_t directly, as well.

Support for Windows 9x shouldn't be in high demand for new software,
as the OSs themselves are unsupported.
Bo Persson
Jul 22 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Giulio | last post by:
I've got to take some data from a CSV file, so i need a good string parser to recognize data to store in variables. using google I found the code below. that seems to be a good solution but I had...
12
by: Casper | last post by:
How would one go about summing up the memmory custom tree structures occupies in memmory? Example: struct node { struct node *parent; unsigned int nChildCount; string folder; //string class...
12
by: Onega | last post by:
Hi I create a simple win32 project (VC2003, windows2003(English) , and do simple paint in WM_PAINT message, when the project use multi-character set, it is OK. but when I change to UNICODE,...
6
by: r.z. | last post by:
This piece of code crashes my app: basic_ifstream<TCHARfile(levelfilepath, ios_base::binary); unsigned int name_length; file.read( (TCHAR*)&name_length, sizeof(unsigned int) ); //crashes here -...
3
by: ujjwaltrivedi | last post by:
Can I use any method to allocate /deallocate memory other than new/ delete operators? Actually the problem is while using delete operator in my ".sqc" files the application crashes. It seems the...
1
by: ranju | last post by:
I am trying to spawn a process (say an exe file) with different user crendentials than that of the current user. 1) Called LogonUserEx() to logon the user and recieve a handle to the token that...
25
by: Norman Diamond | last post by:
I think the current version of _vsnwprintf_s is broken, in ordinary Windows. I'm not completely sure yet but it looks like this breakage is worse than previously known Windows CE breakage of...
1
by: dhanashivam | last post by:
Hi All, I have developed a VC+ dll file which provides a product key for my msi setup file. This VC++ dll work fine together with my setup file. but, my problem is, i have given a message box...
0
by: ramcbe | last post by:
hello, i am very new to vc++.i have the code. #include "windows.h" #include "stdafx.h" // Need the following header files to access the MSI API #include "msi.h" #include "msiquery.h"...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.