Need help on TCHAR

Discussion in 'C++' started by gshy2014@gmail.com, May 23, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. 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-lite/how-to-post.html#faq-5.9 for
    newsgroup suggestions.


    Jonathan
    Jonathan Mcdougall, May 23, 2006
    #2
    1. Advertising

  3. Phlip Guest

    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!!!
    Phlip, May 23, 2006
    #3
  4. Phlip Guest

    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!!!
    Phlip, May 23, 2006
    #4
  5. In message <Raucg.31968$>, Phlip
    <> 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
    Richard Herring, May 23, 2006
    #5
  6. * Richard Herring:
    > In message <Raucg.31968$>, Phlip
    > <> 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?
    Alf P. Steinbach, May 23, 2006
    #6
  7. Phlip Guest

    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!!!
    Phlip, May 23, 2006
    #7
  8. In message <SFEcg.80220$>, Phlip
    <> 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
    Richard Herring, May 23, 2006
    #8
  9. Noah Roberts Guest

    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.
    Noah Roberts, May 23, 2006
    #9
  10. Guest

    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, 2006
    #10
  11. Phlip Guest

    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!!!
    Phlip, May 24, 2006
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    7
    Views:
    1,264
    MaSTeR
    Dec 14, 2004
  2. Bobby
    Replies:
    0
    Views:
    397
    Bobby
    Dec 14, 2004
  3. ree
    Replies:
    7
    Views:
    3,777
  4. sorty
    Replies:
    4
    Views:
    20,720
    Rolf Magnus
    Nov 25, 2003
  5. Replies:
    4
    Views:
    5,224
    Muruganandam
    Feb 2, 2005
Loading...

Share This Page