This is the mail archive of the cygwin@sources.redhat.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: misdefined macro _T in winnt.h


> From: Earnie Boyd <earnie_boyd@yahoo.com>
> 
> "J. J. Farrell" wrote:
> > 
> > > From: Earnie Boyd <earnie_boyd@yahoo.com>
> > >
> > > Eric Paire wrote:
> > > >
> > > > ------  Cut Here  ------  Cut Here  ------  Cut Here  ------
> > > >  #define __DIR "dir"
> > > >  #define _UNICODE
> > > >
> > > >  #include <stddef.h>
> > > >  #include <tchar.h>
> > > >  main() {
> > > >         size_t len = wcslen(_T(__DIR)) + wcslen(_T("dir"));
> > > >         size_t len2 = wcslen(_TEXT(__DIR)) + wcslen(_TEXT("dir"));
> > > >         exit(len);
> > > >  }
> > > > ------  Cut Here  ------  Cut Here  ------  Cut Here  ------
> > >
> > > I do need to know if
> > >   L"dir" == L("dir")
> > > ?  The problem with this macro is the use of the macro concatenation ##
> > > and the order in which the macros are resolved.  Currently we have
> > >   #define _T(x) L ## x
> > > and if you pass a macro FOO as an argument to this macro you get LFOO
> > > returned and not the value of FOO appended to L.  If I change this to
> > >   #define _T(x) L(x)
> > > then I get returned L("bar") where "bar" is the value of FOO.  This
> > > allows the program to compile but does L"bar" == L("bar")?
> > 
> > No. I'm certain of that, more or less ...
> 
> 1) If that is true then what is the purpose of function L()?
> 2) Can someone who has MSVC++ tell me what the _T(__dir) expands to
> using the above example?
> 3) Is it legal to pass a MACRO as an argument to the _T() macro?

Sorry, Earnie, I think I misinterpreted your question - though my
brain must have been elsewhere because my interpretation didn't make
much sense. I thought you were asking if the character sequence

  L"dir"

was syntactically equivalent to the character sequence

  L("dir")

It isn't, but I'm sure you know that!

The usual way to handle this sort of thing is with a second macro
invocation to make use of rescanning of the sequence. Something like:

#define _T(x)    _T_(x)
#define _T_(x)   L ## x

Then if we start with

  _T(__DIR)

after the first pass of macro replacement we get

  _T_("dir")

and after the second pass we get

  L"dir"



--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]