[quoted text, click to view] "Jochen Kalmbach [MVP]" <nospam-Jochen.Kalmbach@holzma.de> wrote in message
news:epacONduFHA.3528@TK2MSFTNGP15.phx.gbl...
> Hi Norman!
>
>> So for my first citation of an example, I was wrong to say that it is not
>> compilable. My question is still meaningful though. Here I will create
>> an example which is different from MSDN's example:
>> CAtlString s( "$B$"$$$&$"$$$&(B" );
>> _ASSERT( s.ReverseFind( '$B$$(B' ) == 4 );
>> This is compilable for the same reason as MSDN's example is compilable,
>> but the result is doubtful. There is a constructor for s that takes a
>> parameter of type YCHAR*, so the ANSI string "$B$"$$$&$"$$$&(B" will be
>> converted to Unicode string L"$B$"$$$&$"$$$&(B" and stored as the initial
>> value of s. In the argument to ReverseFind, the character literal '$B$$(B'
>> has type int (because it consists of more than one c-char) and it
>> undergoes an integral conversion to wchar_t, but I doubt that an integral
>> conversion produces the same value as L'$B$$(B'.
>
> This is a completely different example
Yes, I said I had to adjust my first example. My second example is more
important now. Please look at it again.
[quoted text, click to view] > and has mainly to do with the compiler interpreting the source files!!!
> You need to set the appropriate codepage, so the compiler is able to
> translate the "ANSI"-chars in your source file into the correct codepage.
Huh???????
Windows XP SP2 defaults to the correct code page during installation (932 in
this country). Visual Studio 6, 2003, and 2005 beta obey the existing
setting of the code page (or at least the versions sold in this country do).
I do not have to set anything.
When I install a US version from MSDN, I do have to set Windows regional
options and some Visual Studio options in order to make them resemble
ordinary versions. They work.
However, that is for ANSI characters in my source file. ANSI literals are
not Unicode literals, and this is not because of regional options or
compiler settings, it is because '' literals are not L'' literals.
[quoted text, click to view] > The value of "$B$"$$$&$"$$$&(B" is *not* converted to uncode by the
> compiler!!!
Bingo. Now you know why I said that, even though you are right about
integral conversions occuring, I think that integral conversions will
produce incorrect results.
[quoted text, click to view] > It is converted to MBCS (with the codepage you have choosen)!
It is not converted, it is already MBCS in the first place, in the codepage
that Microsoft chose when Microsoft sold their products in this country.
[quoted text, click to view] > If you want unicode, please use L!
Bingo. Now you really know why I said that, even though you are right about
integral conversions, it is highly doubtful that MSDN's examples will
produce correct results. And that's only for examples which compile
(because of integral conversions), it still doesn't do a thing for examples
which don't compile.
[quoted text, click to view] > The character '$B$$(B' is also converted using the compilers-codepage!
It is not converted at all. The compiler obeys Windows' code page.
[quoted text, click to view] > And it is not suggested to use characters > 126 in your source-code.
Oh really. Do you use German characters in character literals and string
literals in your source programs? Can you figure out why some programmers
who are Japanese or live in Japan or target the Japanese market might use
Japanese characters in their source programs? Sure it's better to use
message catalogs and not use any character literals or string literals at
all in source programs. But C and C++ languages do have character literals
and string literals, and programmers use them. And guess what, they don't
lead to problems. Problems only arise when someone tries to compile them
with foreign regional options set, or execute them with foreign regional
options set.
[quoted text, click to view] >> Notice MSDN's example code:
>> @ //typedef CStringT< TCHAR, StrTraitATL< TCHAR > > CAtlString;
>> @
>> @ CAtlString s( "abcdef" );
>> @ _ASSERT( s.Find( 'c' ) == 2 );
>> @ _ASSERT( s.Find( "de" ) == 3 );
>>
>> Since "de" has type char*, it has no automatic conversion to type
>> wchar_t*, and this should not be compilable.
>
> Yes. This example is simply wrong. Correct should be:
> _ASSERT( s.Find( TEXT("de") ) == 3 );
Why? There is no integral conversion from char* (the type of string literal
"de") to wchar_t* (the type of the XCHAR* parameter to CStringT::Find).
This example is simply wrong because it cannot even compile. You proved
that I was wrong in my first choice of example because integral conversions
yielded compilation with doubtful result, but my second choice of example
correctly proves my complaint. If there is no override for CStringT::Find
to take a parameter of type YCHAR* then this MSDN example does not even
compile.