Re: CString not working as advertised

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi David,

I think the bigger issue with this is that it uses the ACP code page
(whatever is set) to do the conversion to multi-byte so you don't always get
a clean conversion. However, to be fair, I find the conversion feature to
be pretty handy at times when I know I am not doing something that would
mangle my strings. You're right though, it doesn't produce any error
message during compile. That makes me wonder how the OP got this error when
he was compiling.

Tom

"David Wilkinson" <no-reply@xxxxxxxxxxxx> wrote in message
news:%23w1CH%23FZGHA.1016@xxxxxxxxxxxxxxxxxxxxxxx
Joseph M. Newcomer wrote:
On Wed, 19 Apr 2006 15:06:53 -0400, R. Christian Call
<rccall@xxxxxxxxxxxxxx> wrote:


[snip]

The examples given in the MFC library fail miserably most fo the time--
even for simple stuff that I'd expect to work without a hitch. For
instance, I can't do this:

CString kindOfFruit = "bananas";

****
Note that default for VS 2005 is Unicode, so a quoted string like above
is meaningless.
You could either write

CStringA kindOfFruit = "bananans";
or
CStringW kindOfFruit = L"bananas";
or
CString kindOfFruite = _T("bananas");

but what you wrote should not compile, and the error message below is
what you should get.
****

[snip]

Joe:

That's interesting, but I disagree. In VC6, and I think VC7, in a UNICODE
build

CString kindOfFruit = "bananas";

will actually compile, because CString contains "conversion constructors"
which will initialize a CString from either narrow or wide
characters in both ANSI and UNICODE build.

IMO, this is a terrible feature, because (like most automatic conversions)
it prevents the compiler from type-checking the code. But I find it hard
to believe that MS would have removed this feature from VC8, because much
code (not mine!) relies on this feature to convert between narrow/wide
character strings.

David Wilkinson


.



Relevant Pages

  • Re: WG: SI Units - has Ada missed the boat?
    ... I don't remember the details but there was also a way to define the conversion from various units into the generic _UNITS. ... This program would then write the ADA specs and bodies for the conversion. ... The "UNITS" package took about 4 hours to compile and every component took a long time to compile because every expression had to be compared to the myriad of overloads to determine if the expression was valid. ... myint: INTEGER; ...
    (comp.lang.ada)
  • Re: Microsoft Losing Interest in C#?
    ... > The code doesn't compile right now because, IIRC, the JCLA generated a few ... > javaisms in the sections where a direct conversion wasn't possible. ... The JLCA doesn't understand the Comparable interface, ... UUID.cs: error CS0246: The type or namespace name 'MessageFormat' ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [ANNOUNCE] high-res-timers patches for 2.6.6
    ... but all are compile in. ... >>I would have to redo the conversion code. ... can, at boot time, switch to one of the standard clocks and thus disable HRT (or ... I had not considered not using the APIC timer if it was available. ...
    (Linux-Kernel)
  • 50 years of progress in the language
    ... almost every program would compile and run correctly using ... Smaller length alphabetic test onstant strings were treated as ... Conversion between integer variabless and equivalent digit strings ... the character array and the character string. ...
    (comp.lang.fortran)
  • Re: fast and accurate in mixed mode operations
    ... < double using the command dble() in the expressions or would it be ... For the same conversion, the speed and accuracy should be ... precision, then you might need a conversion function. ... There used to be questions about constant conversion at compile ...
    (comp.lang.fortran)