473,387 Members | 3,750 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,387 software developers and data experts.

Need help on TCHAR

Hi, all.
IN Windows, TCHAR is translated to be wchar or char according to
whether UNICODE is defined. Dose the complier handle the UNICODE(define
or not define) according to the OS ?

Many thanks

May 23 '06 #1
10 5800
gshy2...@gmail.com wrote:
Hi, all.
IN Windows, TCHAR is translated to be wchar or char according to
whether UNICODE is defined. Dose the complier handle the UNICODE(define
or not define) according to the OS ?


This newsgroup deals with standard C++, not compiler specific features.
Please see
http://www.parashift.com/c++-faq-lit...t.html#faq-5.9 for
newsgroup suggestions.
Jonathan

May 23 '06 #2
gshy2014 wrote:
IN Windows, TCHAR is translated to be wchar or char according to
whether UNICODE is defined. Dose the complier handle the UNICODE(define
or not define) according to the OS ?


The macro UNICODE (and _UNICODE) are compile time constants. That means they
are set at compile time. No program written in C++ can ever change a #define
or /D constant at run-time. Compiling with and without /DUNICODE will give
you two different executables that will behave differently when run on the
same machine.

Warning: C++ is the topic of this newsgroup. Not UNICODE, or Win32, or the
differences between Win98 and WinNT, or the VC++ compiler. You must ask
complete questions about these things, individually, on their appropriate
newsgroups, to get the best answers. Your current question is on-topic (by
accident), but your next question (how the compiler and header files respond
to the UNICODE flag) will be off-topic here, so you should use Google to
find the best newsgroup.

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
May 23 '06 #3
Jonathan Mcdougall wrote:
IN Windows, TCHAR is translated to be wchar or char according to
whether UNICODE is defined. Dose the complier handle the UNICODE(define
or not define) according to the OS ?


This newsgroup deals with standard C++


Read the question again. ;-)

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
May 23 '06 #4
In message <Ra*******************@newssvr11.news.prodigy.com> , Phlip
<ph******@yahoo.com> writes
Jonathan Mcdougall wrote:
IN Windows, TCHAR is translated to be wchar or char according to
whether UNICODE is defined. Dose the complier handle the UNICODE(define
or not define) according to the OS ?


This newsgroup deals with standard C++


Read the question again. ;-)


I read it three times and I still don't get it. The second word of the
introductory sentence is "Windows" and the third is "TCHAR". When we get
to the actual question, it refers to "the compiler" and "the OS". If
that's not platform-specific, what is?

--
Richard Herring
May 23 '06 #5
* Richard Herring:
In message <Ra*******************@newssvr11.news.prodigy.com> , Phlip
<ph******@yahoo.com> writes
Jonathan Mcdougall wrote:
IN Windows, TCHAR is translated to be wchar or char according to
whether UNICODE is defined. Dose the complier handle the UNICODE(define
or not define) according to the OS ?

This newsgroup deals with standard C++


Read the question again. ;-)


I read it three times and I still don't get it. The second word of the
introductory sentence is "Windows" and the third is "TCHAR". When we get
to the actual question, it refers to "the compiler" and "the OS". If
that's not platform-specific, what is?


I think Phlip's point was the the OP was possibly asking /whether/ TCHAR
was a standard type with some built-in support, "Dose the compiler...".

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 23 '06 #6
Richard Herring wrote:
I read it three times and I still don't get it. The second word of the
introductory sentence is "Windows" and the third is "TCHAR".
Right. And then you pretended you knew nothing about them. This is an
example of why "it's not in the Standard" is sometimes not a useful detector
for topicality.
When we get to the actual question, it refers to "the compiler" and "the
OS". If that's not platform-specific, what is?


We will interpret "/D" in the following as "the thing that predefines things
as a command line argument to the compiler". I am aware little of that is
Standard; all compilers have such a thing, so we could add excess verbiage
in place of "/D" and get away with it...

The question was ambiguous, with two potential:

- does the current OS affect the compiler and turn on
a /D for a given macro?

- does the current OS affect the executing program and
turn a macro on for it?

The answer to the first one is that some "make" systems, which are
off-topic, will select which macros to compile with, but they never select
the optional ones; they leave them up to you.

The answer to the second one is the compiler locks in all #define and /D
values when it compiles, so nothing can ever change these at run-time.

The first answer is of marginal topicality, but it's something of interest
to all C++ programmers, and it would hopefully resolve this thread.

The second answer is on topic because it shows someone needs to understand
"compile-time constants".

Note I took the dreaded terms Windows, UNICODE, and TCHAR out of the
questions. The best way to improve newsgroup quality is to seek good
on-topic answers, if they are at all possible, while recommending other
newsgroups for the off-topic bits.

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
May 23 '06 #7
In message <SF*******************@newssvr13.news.prodigy.com> , Phlip
<ph******@yahoo.com> writes
Richard Herring wrote:
I read it three times and I still don't get it. The second word of the
introductory sentence is "Windows" and the third is "TCHAR".
Right. And then you pretended


In the case of "TCHAR", no pretence was necessary. I write a good deal
of code for Windows, but I've never had to deal with something called
TCHAR.
you knew nothing about them.
Actually, in the first instance I simply kept quiet, having nothing
useful to tell the original poster.
This is an
example of why "it's not in the Standard" is sometimes not a useful detector
for topicality.
When we get to the actual question, it refers to "the compiler" and "the
OS". If that's not platform-specific, what is?
We will interpret "/D" in the following as "the thing that predefines things
as a command line argument to the compiler". I am aware little of that is
Standard; all compilers have such a thing, so we could add excess verbiage
in place of "/D" and get away with it...

The question was ambiguous, with two potential:

- does the current OS affect the compiler and turn on
a /D for a given macro?

- does the current OS affect the executing program and
turn a macro on for it?

The answer to the first one is that some "make" systems, which are
off-topic, will select which macros to compile with,


And some compilers will do the same. I wouldn't be surprised to find
that the ones targeting Windows will make different selections according
to whether they are running under 95 or 98 or 2000 or NT or XP ...
but they never select
the optional ones; they leave them up to you.
Which is less than helpful unless you can determine _which_ ones are
optional.

The answer to the second one is the compiler locks in all #define and /D
values when it compiles, so nothing can ever change these at run-time.

The first answer is of marginal topicality, but it's something of interest
to all C++ programmers, and it would hopefully resolve this thread.
All it does is to describe the mechanism, not the actual outcome -
_which_ macros get defined as what in a given environment?
The second answer is on topic because it shows someone needs to understand
"compile-time constants".
Only *if* your interpretation of the second potential meaning of the
question is valid; otherwise it's just a confusing digression.
Note I took the dreaded terms Windows, UNICODE, and TCHAR out of the
questions. The best way to improve newsgroup quality is to seek good
on-topic answers,
Of course
if they are at all possible,
.... and there's the rub...
while recommending other
newsgroups for the off-topic bits.

The degree of _useful_ on-topic information you can supply rapidly
becomes marginal.

Compare:

"some systems will select which macros to compile with, but they never
select the optional ones. They don't change at run-time"

"under compiler X and OS Y, the following macros are automatically
defined and therefore TCHAR is compiled as..."

--
Richard Herring
May 23 '06 #8

Alf P. Steinbach wrote:
I think Phlip's point was the the OP was possibly asking /whether/ TCHAR
was a standard type with some built-in support...


Which in the end it is as it's just a define for either wchar or char.
TCHAR itself is an non-standard define but you can use it and still
remain 100% within the standard. Of course this wouldn't be
adventageous as the typedef is meant to be used in conjunction with
non-standard libraries on a very particular platform.

May 23 '06 #9
Thank you all for explanations.
Philp got my question: does the current OS affect the complier and turn
on a /D for a given macro. However, I am not clear about Philp's
answer. Philp, your answer is 'yes' or 'no'?

Richard Herring, Does you mean that some compliers and OS will
automatically determine what TCHAR is compiled as: wchar or char, and
the programmers need not turn on '/D' when compling?

Maybe, I posted an off-topic questions here. However, I think some C++
programmers will benefit from it.

May 24 '06 #10
gshy2014 wrote:
Philp got my question: does the current OS affect the complier and turn
on a /D for a given macro. However, I am not clear about Philp's
answer. Philp, your answer is 'yes' or 'no'?
Now I don't know the question. Pick one:

A> At compile time, does the compiler detect the OS type and turn on
/DUNICODE?

B> At runtime, does the UNICODE macro change?

The answer to A is "Some compilation systems do that to some /D macros, and
they are all off-topic. I know of no Win32 compiler which does that for
UNICODE, and doing it would defeat the (off-topic) purpose of the UNICODE
macro, which is to compile for a target _different_ from the current OS -
either Win95-derived or WinNT-derived.

You will get a much better answer if you use Google Groups to find a topical
newsgroup, and then post a new, complete question to it.

(And the time has finally come to forget about any platform derived from
Win95!)

The answer to B is (on-topic) never ever ever, because all macros get
compiled at compile time. When they trigger "conditional compilation" (look
it up) the resulting code locks-down and never changes at runtime. Generally
speaking, only an 'if' statement will change things at runtime!
Richard Herring, Does you mean that some compliers and OS will
automatically determine what TCHAR is compiled as: wchar or char, and
the programmers need not turn on '/D' when compling?
No, they never will, and don't ask him that question again. Please read our
thread carefully to understand that we cannot give good answers to off-topic
questions here. We generally do our best to give bad answers, as a
cautionary tale. ;-)
Maybe, I posted an off-topic questions here. However, I think some C++
programmers will benefit from it.


Thanks, but that's not the point of topicality. I can review Richard's
answer, and he mine, when we answer an _on_topic_ question. But if you ask
an off-topic question about a system I know and Richard does not, he cannot
review or correct my answer. So posting to the most topical newsgroup (
probably news:microsoft.public.vc.language ) is in everyone's best interests
here.

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
May 24 '06 #11

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

Similar topics

7
by: ree | last post by:
I need to use a function from a wininet library, it requires the use of const TCHAR. The problem is the value needs to be calculated, so at the end I have this string but I am having troubles...
4
by: sorty | last post by:
Hi, I have read in many places that TCHAR can be 'char' or 'wchar_t' depending on ANSI or UNICODE. I have also read that LPTSTR is a long pointer to a TCHAR. I am confused about the...
4
by: muroogan | last post by:
I read a text file into a char variable char tchar; I want to trim leading spaces (Left trim).How can I do that in C++. Any input will be appreciated.
2
by: SteveK | last post by:
I cannot for the life of me figure out how to TCHAR to be defined as an unsigned char as it is in out 6.0 project. I created a fresh VS 2003 project and played around with the settings and still...
3
by: Sky Sigal | last post by:
I coming unglued... really need some help. 3 days chasing my tail all over MSDN's documentation ...and I'm getting nowhere. I have a problem with TypeConverters and storage of expandableobjects...
4
by: drazbliz | last post by:
Hello, I am running the following code segment in visual studio 2005. size_t cchSize = 10*sizeof(TCHAR); LPTSTR temp = (LPTSTR)malloc(cchSize); temp = '\0'; _tcscat_s(temp, cchSize,...
3
by: Michael | last post by:
Hi all, I'm having trouble PInvoking a TCHAR within a struct. I'll paste the specific struct's API definition below. I've tried so many numerous variations. The main Win32 error I get is...
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 -...
2
by: 97612 | last post by:
Below are my codes,and I want to use TCHAR to replace the char /**************************************** const char* ptr = NULL; char newPath; ptr = strrchr(absPath, '.'); strncpy(newPath,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.