This is the mail archive of the
cygwin@sources.redhat.com
mailing list for the Cygwin project.
RE: misdefined macro _T in winnt.h
- To: "Cygwin" <cygwin at cygwin dot com>
- Subject: RE: misdefined macro _T in winnt.h
- From: "Lothan" <lothan at newsguy dot com>
- Date: Mon, 5 Feb 2001 22:08:28 -0800
I suppose we might consider this the definitive answer. I pasted in this
source code:
#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);
}
I ran it through the preprocessor for both Borland C++ 5.0 and Microsoft
Visual C++ 6.0 and got identical output from both preprocessors.
main()
{
size_t len = wcslen(L"dir") + wcslen(L"dir");
size_t len2 = wcslen(L"dir") + wcslen(L"dir");
exit(len);
}
I get this output from gcc:
main()
{
size_t len = wcslen(L__DIR ) + wcslen(L"dir" );
size_t len2 = wcslen(L__DIR ) + wcslen(L"dir" );
exit(len);
}
In my opinion, the output from Borland C++ and MSVC is correct. The output
from gcc is dead wrong. Not surprisingly, the declarations are also
identical for Borland C++ and MSVC:
#define _T(x) __T(x)
#define _TEXT(x) __T(x)
#define __T(x) L ## x
The relevant declarations from gcc are:
#define _TEXT(x) L ## x
#define _T(x) L ## x
If you replace the erroneous definitions in tchar.h with the correct
definitions from above, it parses correctly.
> > > #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?
>
> Earnie.
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>
>
> --
> Want to unsubscribe from this list?
> Check out: http://cygwin.com/ml/#unsubscribe-simple
>
--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple