<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Stan Lippman's BLog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/slippman/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/slippman/feed.xml</link>
    <description>C++/CLI</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:27:24 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>The String Literal Returns</title>
      <link>https://docs.microsoft.com/archive/blogs/slippman/the-string-literal-returns</link>
      <pubDate>Wed, 08 Dec 2004 00:26:00 GMT</pubDate>
      <dc:creator><![CDATA[slippman]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/slippman/2004/12/08/the-string-literal-returns/</guid>
      <description><![CDATA[In the last entry, I celebrated what I felt was an elegant solution to the problem of the string...]]></description>
      <content:encoded><![CDATA[<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">In the last entry, I celebrated what I felt was an elegant solution to the problem of the string literal in the context of overload function resolution. But it turns out there is another area in which the string literal proves problematic. Who would have thought such a foobar kind of entity could cause so much trouble? It's these kinds of ambushes that makes the extension of a language so unpredictable. <span style="mso-spacerun: yes">&nbsp;</span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p>&nbsp;</o:p></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">So, here's the problem.</p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>throw "fritz";</p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">what does the compiler do? it has to set everything up at compile-time, then it actually gets handled by a run-time library that makes use of a limited form of type reflection to figure the kind of object having been thrown. </p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">there's no context, really. we don't know if the person is going to catch x, y, or z, so we can't know what to throw in any particular instance. this is all set up at compile-time. </p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">Now, here is the rub:</p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>void f()</p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>try { g(); }</p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>catch ( String^ s ) {}</p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>catch ( const char* pcs ) {}</p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>void g()</p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>throw "fritz";</p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">What gets caught? what an impossible question. one could argue if we are compiling for the CLR, then String^ should match, and if we are in native, and so on. But there's no reason to believe that just because we are compiling for the CLR, people are using String and not just const char*. </p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">So, a string literal is thrown as a type const char*, not as String^. <span style="mso-spacerun: yes">&nbsp;</span>My first reaction was, gosh, that's terrible. Then, I thought, what am I thinking? It seems a very small matter. It's not even something I would run into since I don't throw anything but class objects. I just add it for completeness. </p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">I think if this bothers you, then you are bothered by our entire effort. Just as a sounding. That is, not everybody is happy with our work on C++/CLI. There are some folks out there that feel concern that we are somehow messing with their language, and we shouldn't be allowed to do that.</p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">we aren't doing it that way at all. We have really wanted to be good c++ citizens while being excellent Microsoft employees. I have never felt any pressure to compromise either while I have been here. We have had an extraordinary degree of freedom not simply in our design, but in our being able to reach out and work with the general c++ community. this language is a coalition. I think we have all wanted to put the best face on C++ in what we regard as an otherwise hostile environment for C++. We think this is a win-win situation for everyone. if you don't like something, you should let us know. we're not a hundred thousand leagues removed from our users. if you want to use the language, you have every right to tell us what you think about it; how you find it; what you want. if you make a good case for it, I think it could be done. that's just my opinion. but I think we have an opportunity to together as a C++ community put forth C++ in an otherwise hostile environment that for some unbelievable reason thinks C# or Java comes anywhere near being as good a language. I don't understand it. It's not a question of knocking those languages. They took so much from C++ -- it's not hard, after all the hard stuff was worked out, to go back and clean it up. sure. C++ is messy. it was real hard to do. it was getting done while we were using it. we didn't know where it was going. Bjarne was implementing it, using it, it became the tool we all used to make our living. we wanted it to be the best possible language for programmers. at least I did. I don't have a philosophy. I don't make standards. I just program and write. and I do that best in C++. C# and Java mean nothing to me. Now I have my own language to use on .NET. That was my personal agenda in all this. I think you should check it out. </p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">it was a great adventure. I find C++/CLI is something interesting again about C++ for me anyway. I'm not a fan of standards. I've never finally been involved in one. It's making a language that interests me, not in clean-up and all that necessary stuff for real-world production. I don't have the head for that.</p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">so, I just wanted to make a personal statement. I have watched the team here for almost 3 years. I worked with them sometimes. I snarled at them sometimes. I was fed up with them once or twice. and yet they have produced something really wonderful in my opinion, and it is much better than I had dared imagine. I just love it. I can't wait to program with it – I'd like to drop everything and just start. this is exactly what I have been waiting for. to have a language to program .net. we didn't have one before. </p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">C++/CLI is a entry visa nto what I call 3-dimensional programming. The CLR gives you the run-time as an entity to query, to modify, to almost in a sense be alive in. everything in a native program has to be done at compile-time. that is way too early for me to know exactly what needs to be done in many interesting environments. can't I wait? I'm not that performance critical that I need the machine. </p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">my first analogy was going to be between the traditional Disney animation and the Pixar CGI, but I think a better analogy is between an instinct and a decision. that is, an instinct is the trigger of a built-in behavior that is insulated from and unaffected by the environment. a decision considers the environment (context) and memory (past behavior) in order to choose a best action. this is what is missing from native static programming. it really can't be smart enough for the kinds of problems we need to solve now in my estimate. I can't prove that. </p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">I gave a talk at Disney Feature Animation a few months ago about C++/CLI, and a friend of mine who I love dearly, asked me, what do I need that for? he is in charge of plug-in 3D tools for Maya, a modeling toolkit for computer graphics. And he is right. But we need it I believe as a community going forward. and in that sense, we have opened that doorway for the C++ programmer. The worst case scenario was that the price of admission to this world was to have to renounce C++ -- I mean, mea culpa. we're such savages – we worry about performance, we break the type system, we make use of the underlying machine, we don't follow enough rules. we're loose cannons. Can't have loose cannons. I personally didn't want to accept that as being a true statement.</p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">But you cannot argue something like that. I can't say, hypothetically, C++ can be as good a language under .NET as Java or C#. Nobody would hear that – they would just see Lippman being defensive, or delusional. you have to demonstrate it. That's the only way to really convince people. That's the only way I can ever convince myself in fact. So, that is what C++/CLI means to me.</p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">I know Bjarne has his reservations and dislikes. Well, so do we all, if truth be told. But it's still just so wonderful overall. who cares if it's not perfect. I don't – I haven't gotten anything perfect, trust me. i don't know if it is better than this or that or the next thing. but it's really pretty good and i'm going to use it. and we really did it as a team.</p>]]></content:encoded>
    </item>
    <item>
      <title>The Type of a String Literal Revisited ...</title>
      <link>https://docs.microsoft.com/archive/blogs/slippman/the-type-of-a-string-literal-revisited</link>
      <pubDate>Sat, 04 Dec 2004 09:14:00 GMT</pubDate>
      <dc:creator><![CDATA[slippman]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/slippman/2004/12/04/the-type-of-a-string-literal-revisited/</guid>
      <description><![CDATA[In the course of these entries, I have twice addressed the issue of the type of a string literal...]]></description>
      <content:encoded><![CDATA[<p class="textnoindent" style="MARGIN: 6pt 0in"><font face="Tahoma">In the course of these entries, I have twice addressed the issue of the type of a string literal under C++/CLI -- in particular when resolving an overloaded function call. The issue is illustrated in the following example,</font></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3">public ref class R {</font></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3">public:</font></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3">&nbsp; void foo( System::String^ ); // (1)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></font></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>void foo( std::string );<span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </span>// (2)</font></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3">&nbsp; void foo( const char* );<span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </span>// (3)</font></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3">};</font></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in">&nbsp;</p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3">void bar( R^ r )<o:p></o:p></font></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3">{</font></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3">&nbsp; // which one?</font></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3">&nbsp; r-&gt;foo( "Pooh" );</font></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3">}<o:p></o:p></font></span></p> <p class="textnoindent" style="MARGIN: 6pt 0in"><font face="Tahoma">In the original Managed Extensions for C++, the invocation of <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">foo()</span> within <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">bar()</span> resolved to (3), exactly the same as it does under ISO-C++. That is,</font></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3">void bar( R^ r )<o:p></o:p></font></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><font size="3"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">{</span><span style="FONT-FAMILY: 'Courier New'"><o:p></o:p></span></font></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3">&nbsp; // under Managed Extensions to C++, resolved to<o:p></o:p></font></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>// void foo( const char* );<o:p></o:p></font></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><font size="3"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp; r-&gt;foo( "Pooh" );</span><span style="FONT-FAMILY: 'Courier New'"><o:p></o:p></span></font></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-FAMILY: 'Courier New'">}</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p></o:p></span></p> <p class="textnoindent" style="MARGIN: 6pt 0in"><font face="Tahoma">To briefly review: In ISO-C++, the type of "Pooh" is <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">const</span><span style="FONT-SIZE: 11pt"> </span><span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">char[5]</span>. There is no <i>exact</i> match of "Pooh" to any of the three instances of <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">foo()</span>. However, the <i>trivial</i> <i>conversion</i> of <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">const</span><span style="FONT-SIZE: 11pt"> </span><span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">char[5]</span> to <span style="FONT-FAMILY: 'Courier New'">const</span> <span style="FONT-FAMILY: 'Courier New'">char*</span> represents a best match, and this is why (3) is invoked. There was no built-in notion of a string literal having any relationship to <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">System::String</span>. </font></p> <p class="textnoindent" style="MARGIN: 6pt 0in"><font face="Tahoma">And this was changed in the design of C++/CLI. Actually, it was changed twice, and that is the talking point of this entry – to explain why the initial change had to be further refined. </font></p> <p class="textnoindent" style="MARGIN: 6pt 0in"><font face="Tahoma">The overall effect of the change is to extend dual citizenship to a string literal compiled for the CLI. The initial change is described in my earlier entry entitled <i>String Literals are now a Trivial Conversion to String</i>. Here is a brief review of the issue.</font></p> <p class="textnoindent" style="MARGIN: 6pt 0in"><font face="Tahoma">The first question is, what is the exact type of "Pooh" within C++/CLI? One answer is, <i>well, obviously, it is of type </i><i><span style="FONT-FAMILY: 'Courier New'">const</span> </i><i><span style="FONT-FAMILY: 'Courier New'">char[5]</span> – otherwise, it could not be compatible with ISO-C++</i>. We can't change that.</font></p> <p class="textnoindent" style="MARGIN: 6pt 0in"><font face="Tahoma">The initial solution, therefore, was to introduce a new trivial conversion, that of a string literal to a <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">System::String</span>, that is of equal precedence with the trivial conversion of a string literal to <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">const</span> <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">char*</span>. This provides a somewhat elegant symmetry, but in practice results in a flurry of ambiguous calls. For example, under this design, the invocation of <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">foo()</span> now fails,</font></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3">void bar( R^ r )<o:p></o:p></font></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><font size="3"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">{</span><span style="FONT-FAMILY: 'Courier New'"><o:p></o:p></span></font></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3">&nbsp; // under interim C++/CLI, flagged as ambiguous<o:p></o:p></font></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>// the following two candidate functions are equally good …<o:p></o:p></font></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>//<span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>void foo( System::String^ );<o:p></o:p></font></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>// <span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>void foo( const char* );<o:p></o:p></font></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><font size="3"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp; r-&gt;foo( "Pooh" );</span><span style="FONT-FAMILY: 'Courier New'"><o:p></o:p></span></font></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-FAMILY: 'Courier New'">}</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p></o:p></span></p> <p class="textnoindent" style="MARGIN: 6pt 0in"><font face="Tahoma">To disambiguate the call, the user would have to provide an explicit cast,</font></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3">void bar( R^ r )<o:p></o:p></font></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3">{</font></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3">&nbsp; // ok: void foo( System::String^ );<o:p></o:p></font></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3">&nbsp; r-&gt;foo( safe_cast&lt;String^&gt;( "Pooh" ));</font></span></p> <p class="textnoindent" style="MARGIN: 6pt 0in 6pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3">}<o:p></o:p></font></span></p> <p class="textnoindent" style="MARGIN: 6pt 0in"><font face="Tahoma">In practice, in nearly every case, the C++/CLI programmer wished to have the <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">String</span> instance invoked in preference to the C-style string instance. And so giving equal precedence to both conversions was both a step forward (in recognizing the special relationship of a string literal to <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">System::String</span> under the CLI) and two steps back (the presence of the <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">const</span> <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">char*</span> argument in effect neutralized that relationship (first step back) and required an explicit cast to resolve (second step back) ).</font></p> <p class="textnoindent" style="MARGIN: 6pt 0in"><font face="Tahoma">So, we had to fix that. That is, under the CLI, we want a string literal to more closely be a kind of <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">System::String</span> than <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">const</span> <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">char*</span>. The question was, how could that be achieved without breaking ISO-C++ compatibility? How might you resolve that?</font></p> <p class="text" style="MARGIN: 6pt 0in; TEXT-INDENT: 0in"><font face="Tahoma">The insight to resolve this is to realize that the dual citizenship of a string literal applies to its fundamental type, not to its set of trivial conversions. <span style="mso-bidi-font-size: 12.0pt">In effect, under C++/CLI, the underlying type of a string literal such as "Pooh" is <i>both</i> </span><span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">const</span><span style="mso-bidi-font-size: 12.0pt"> </span><span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">char[5]</span><span style="mso-bidi-font-size: 12.0pt"> (its native inheritance) and </span><span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">System::String</span><span style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt"> </span><span style="mso-bidi-font-size: 12.0pt">(its managed underlying unified type). Under C++/CLI, the string literal is an exact match to </span><span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">System::String</span><span style="mso-bidi-font-size: 12.0pt"> and the trivial conversion to </span><span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">const</span> <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">char*</span><span style="mso-bidi-font-size: 12.0pt"> is not considered. That is, under the revised C++/CLI language specification, the ambiguity has been resolved in favor of </span><span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">System::String</span><span style="mso-bidi-font-size: 12.0pt">,<o:p></o:p></span></font></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3">void bar( R^ r )<o:p></o:p></font></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><font size="3"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">{</span><span style="FONT-FAMILY: 'Courier New'"><o:p></o:p></span></font></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3">&nbsp; // ok: under current C++/CLI, <o:p></o:p></font></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>//<span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </span>void foo( System::String^ );<o:p></o:p></font></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><font size="3"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><span style="mso-spacerun: yes">&nbsp; </span></span><span style="FONT-FAMILY: 'Courier New'"><o:p></o:p></span></font></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><font size="3"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp; r-&gt;foo( "Pooh" );</span><span style="FONT-FAMILY: 'Courier New'"><o:p></o:p></span></font></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"><font size="3">}<o:p></o:p></font></span></p> <p class="text" style="MARGIN: 6pt 0in; TEXT-INDENT: 0in"><font face="Tahoma">This reflects a fundamental difference between <i style="mso-bidi-font-style: normal"><span style="FONT-SIZE: 11pt">ISO-C++</span></i> and <i style="mso-bidi-font-style: normal"><span style="FONT-SIZE: 11pt">C++/CLI</span></i> in their type systems. In <i style="mso-bidi-font-style: normal"><span style="FONT-SIZE: 11pt">ISO-C++</span></i>, types are independent except when explicitly part of the same class inheritance hierarchy. Thus, there is no implicit type relationship between a string literal and the <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: 'Courier New'">std::string</span> class type, even though they share a common abstraction domain. </font></p> <p class="text" style="MARGIN: 6pt 0in; TEXT-INDENT: 0in"><font face="Tahoma"><i style="mso-bidi-font-style: normal"><span style="FONT-SIZE: 11pt">C++/CLI</span></i>, on the other hand, supports a <i style="mso-bidi-font-style: normal">unified</i> type system. Every type, including literal values, is implicitly a kind of <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: 'Courier New'">Object</span>. This is why we can call methods through a literal value or an object of the built-in types. The value <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: 'Courier New'">5</span> is of type <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: 'Courier New'">Int32</span>. The string literal is of type <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: 'Courier New'">String</span><span style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 12.0pt">. It just doesn't work to treat a string literal as either more like or equal to a C-Style string.</span></font></p> <p class="text" style="MARGIN: 6pt 0in; TEXT-INDENT: 0in"><font face="Tahoma">The integrated conversion hierarchy allows a working ISO-C++ program to continue to exhibit the same behavior when compiled for the CLI, while a new C++/CLI program exercising the CLI types reflects the new type priority of the string literal. </font></p> <p class="text" style="MARGIN: 6pt 0in; TEXT-INDENT: 0in"><span style="mso-bidi-font-size: 12.0pt"><font face="Tahoma">Most readers and programmers have little patience with this level of detail, and often point to discussions of C++ type conversions as evidence of its complexity. However, I don't think that is quite fair. The existence of these rules is necessary if one is to reach an intuitive language behavior and guarantee a uniform behavior across implementations. It is because the language generally behaves in a type-intuitive way that allows programmers in fact to ignore these details.<o:p></o:p></font></span></p> <p class="text" style="MARGIN: 6pt 0in; TEXT-INDENT: 0in"><font face="Tahoma">While the length of this discussion might seem disproportionate to the topic's importance, it strikes me as a canonical example of the extent to which we have had to work to integrate the CLI type system into the ISO-C++ semantic framework. This should also suggests certain good practices when a native class is being recast to a CLI class type. It is better, for example, to refashion the set of member functions accepting string literals rather than simply stirring in an additional <span style="FONT-FAMILY: 'Courier New'">String</span> instance to our stew of overloaded functions, seasoning it to local taste.</font></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></p>]]></content:encoded>
    </item>
    <item>
      <title>A Primer on the Interior Pointer</title>
      <link>https://docs.microsoft.com/archive/blogs/slippman/a-primer-on-the-interior-pointer</link>
      <pubDate>Fri, 27 Aug 2004 01:07:00 GMT</pubDate>
      <dc:creator><![CDATA[slippman]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/slippman/2004/08/27/a-primer-on-the-interior-pointer/</guid>
      <description><![CDATA[A value type is typically not subject to garbage collection except in two cases: (a) when it is the...]]></description>
      <content:encoded><![CDATA[<p class="textnoindent" style="MARGIN: 6pt 0in"><font face="Tahoma">A value type is typically not subject to garbage collection except in two cases: (a) when it is the subject of a box operation, either explicit or implicit, such as,</font></p> <p class="codefirstline" style="MARGIN: 6pt 0in 0pt 0.5in"><font face="Courier New" size="2">void f( int ix ) </font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Courier New" size="2">{</font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>// explicit placement on the CLI heap</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>int^ result = gcnew int( -1 );</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p><font face="Courier New" size="2">&nbsp;</font></o:p></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>// exercise result …</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><o:p><font face="Courier New" size="2">&nbsp;</font></o:p></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>// implicit boxing of the integer value ix …</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>Console::WriteLine( "{0} :: {1}", ix, result );</font></font></p> <p class="codelastline" style="MARGIN: 0in 0in 12pt 0.5in"><font face="Courier New" size="2">};</font></p> <p class="textnoindent" style="MARGIN: 6pt 0in"><font face="Tahoma">and (b) when it is contained within a reference type either as a member or as an element of a <i style="mso-bidi-font-style: normal"><span style="FONT-SIZE: 11pt">CLI</span></i> array. For example,</font></p> <p class="codefirstline" style="MARGIN: 6pt 0in 0pt 0.5in"><font face="Courier New" size="2">public enum class Color </font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </span>{ white, red, orange, yellow, green, blue, indigo, violet };</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><o:p><font face="Courier New" size="2">&nbsp;</font></o:p></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Courier New" size="2">public value class Point </font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Courier New" size="2">{</font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>Color m_color;</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>float m_x, m_y;</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><o:p><font face="Courier New" size="2">&nbsp;</font></o:p></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>// …</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Courier New" size="2">};</font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><o:p><font face="Courier New" size="2">&nbsp;</font></o:p></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Courier New" size="2">public ref class Rectangle </font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Courier New" size="2">{</font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>Point bottom_left;</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>Point top_right;</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><o:p><font face="Courier New" size="2">&nbsp;</font></o:p></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>// …</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Courier New" size="2">};</font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><o:p><font face="Courier New" size="2">&nbsp;</font></o:p></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Courier New" size="2">void f( Point p )</font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Courier New" size="2">{</font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>Rectangle<span style="mso-spacerun: yes">&nbsp; </span>^hit = gcnew Rectangle( -2, -2, 2, 2 ); </font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>array&lt;int&gt; ^fib = gcnew int(8){ 1,1,2,3,5,8,13,21 };</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><span style="mso-spacerun: yes"><font face="Courier New" size="2">&nbsp;&nbsp;&nbsp; </font></span></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>// …</font></font></p> <p class="codelastline" style="MARGIN: 0in 0in 12pt 0.5in"><font face="Courier New" size="2">} </font></p> <p class="text" style="MARGIN: 6pt 0in"><font face="Tahoma">In <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">f()</span>, we allocate two <i style="mso-bidi-font-style: normal">whole</i> objects on the <i style="mso-bidi-font-style: normal"><span style="FONT-SIZE: 11pt">CLI</span></i> heap, a <font size="3"><font face="Tahoma"><span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">Rectangle</span> and an array of eight integer elements. The </font><font face="Tahoma"><span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">Rectangle</span></font></font> object contains two interior value class <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">Point</span> members. These are located on the <i style="mso-bidi-font-style: normal"><span style="FONT-SIZE: 11pt">CLI</span></i> heap as fixed offsets into the area allocated to the containing <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">Rectangle</span>. Within each <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">Point</span> are two floating point members and a <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">Color</span> member. These are also located on the <i style="mso-bidi-font-style: normal"><span style="FONT-SIZE: 11pt">CLI</span></i> heap as fixed offsets into the two interior <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">Point</span> objects. </font></p> <p class="text" style="MARGIN: 6pt 0in"><font face="Tahoma">If the <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">Rectangle</span> object is relocated during a sweep of the garbage collector, all its interior members, of course, are relocated as well. The same is true with a <i style="mso-bidi-font-style: normal"><span style="FONT-SIZE: 11pt">CLI</span></i> array. When the array is relocated, the addresses of each of its elements change as well. We cannot safely assign the address of any interior member or array element to a non-tracking pointer or reference. This isn't just a pitfall that we must learn to recognize and sidestep. Rather, the language disallows it. Our attempt results in a compile-time error. For example,</font></p> <p class="codefirstline" style="MARGIN: 6pt 0in 0pt 0.5in"><font face="Courier New" size="2">// error: cannot assign an interior member </font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Courier New" size="2">//<span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>to a non-tracking pointer …</font></p> <p class="codelastline" style="MARGIN: 0in 0in 12pt 0.5in"><font face="Courier New" size="2">Point *p_bl = hit-&gt;BottomLeft;</font></p> <p class="text" style="MARGIN: 6pt 0in"><font face="Tahoma">We need a form of tracking entity to hold the address of an interior member. What are some of the requirements on this entity? Well, one common pattern we felt necessary to support is that of an iterator – in particular when applied to the elements of a <i style="mso-bidi-font-style: normal"><span style="FONT-SIZE: 11pt">CLI</span></i> array. For example,</font></p> <p class="codefirstline" style="MARGIN: 6pt 0in 0pt 0.5in"><font face="Courier New" size="2">void f( array&lt;int&gt; ^fib )</font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Courier New" size="2">{</font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><i style="mso-bidi-font-style: normal">SomeTrackingPointerNotation</i> begin = &amp;fib[0];</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><i style="mso-bidi-font-style: normal">SomeTrackingPointerNotation</i> end = &amp;fib[ fib-&gt;Length ];</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><o:p><font face="Courier New" size="2">&nbsp;</font></o:p></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>for ( ; begin != end; ++begin )</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>// …</font></font></p> <p class="codelastline" style="MARGIN: 0in 0in 12pt 0.5in"><font face="Courier New" size="2">} </font></p> <p class="text" style="MARGIN: 6pt 0in"><font face="Tahoma">Our <i style="mso-bidi-font-style: normal"><span style="FONT-SIZE: 11pt">SomeTrackingPointerNotation</span></i> needs to support pointer arithmetic. That is, when we write <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">++begin</span>, this does not increment the address by 1, but rather by the size of the element type. For example, since array element are of type <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">int</span>, each increment must add <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">sizeof(int)</span> to the current address value. </font></p> <p class="text" style="MARGIN: 6pt 0in"><font face="Tahoma">Neither the tracking handle (<span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">^</span>) nor its indirect cousin, the tracking reference (<span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">%</span>), supports pointer arithmetic. Moreover, a tracking reference does not support pointer comparison, such as </font></p> <p class="codeoneline" style="MARGIN: 6pt 0in 6pt 0.5in"><font face="Courier New" size="2">begin != end </font></p> <p class="text" style="MARGIN: 6pt 0in"><font face="Tahoma">Like a native reference, a tracking reference, once initialized, serves as an alias to the underlying object to which it refers. The comparison is not of the two tracking addresses but of the values stored at those addresses. This is not the iterator semantics we need.</font></p> <p class="text" style="MARGIN: 6pt 0in"><font face="Tahoma">In a native design, we decide whether to go with a pointer or a reference declaration based on two primary factors: </font></p> <p class="text" style="MARGIN: 6pt 0in 6pt 61.35pt; TEXT-INDENT: -39.75pt; tab-stops: list 61.35pt; mso-list: l0 level1 lfo1"><span style="mso-fareast-font-family: Palatino; mso-bidi-font-family: Palatino"><span style="mso-list: Ignore"><font face="Palatino">(1)</font><span style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><font face="Tahoma">if the object we wish to refer to is unavailable at the time of declaration, then we must declare a pointer and set it to null. A reference requires an initial object.<span style="mso-spacerun: yes">&nbsp; </span>So does a tracking reference.</font></p> <p class="text" style="MARGIN: 6pt 0in 6pt 61.35pt; TEXT-INDENT: -39.75pt; tab-stops: list 61.35pt; mso-list: l0 level1 lfo1"><font face="Tahoma"><span style="mso-fareast-font-family: Palatino; mso-bidi-font-family: Palatino"><span style="mso-list: Ignore">(2)<span style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span>if we wish to refer to more than a single object during the lifetime of the declaration, then we must also declare a pointer. A reference cannot be reset to refer to a second or subsequent object. Neither can a tracking reference. </font></p> <p class="text" style="MARGIN: 6pt 0in"><font face="Tahoma">What this suggests is that we need an analogous choice when the constraints of a tracking reference make it ill-suited to our design. A third, more flexible form of tracking entity, the interior pointer (<span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">interior_ptr&lt;&gt;)</span>, is given over to this role. It can refer to no object (but only by setting it to nullptr, not <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">0</span>). And it can be reset to refer to a second or subsequent object. Moreover, it supports both pointer arithmetic and pointer comparison. For example,</font></p> <p class="codefirstline" style="MARGIN: 6pt 0in 0pt 0.5in"><font face="Courier New" size="2">int sum( array&lt;int&gt; ^arr )</font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Courier New" size="2">{</font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>if ( ! arr )</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>return 0;</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><o:p><font face="Courier New" size="2">&nbsp;</font></o:p></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>interior_ptr&lt;int&gt; begin = nullptr;</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>interior_ptr&lt;int&gt; end = &amp;arr[ fib-&gt;Length ];</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>int sum = arr[0];</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><o:p><font face="Courier New" size="2">&nbsp;</font></o:p></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>for ( begin = &amp;arr[1]; begin != end; ++begin )</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>sum += *begin;</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><o:p><font face="Courier New" size="2">&nbsp;</font></o:p></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>return sum;</font></font></p> <p class="codelastline" style="MARGIN: 0in 0in 12pt 0.5in"><font face="Courier New" size="2">} </font></p> <p class="text" style="MARGIN: 6pt 0in"><font face="Tahoma">The declaration of an interior pointer is limited to local objects, including function parameters and return types. If we don't provide an initial value, the compiler automatically inserts code to set it to <span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">nullptr</span> – so the explicit initialization in the above example is not strictly necessary. The type specified within the template brackets identifies the kind of object addressed; we do not indicate a pointer within the brackets unless we intend two or more levels of indirection. For example, </font></p> <p class="codefirstline" style="MARGIN: 6pt 0in 0pt 0.5in"><font face="Courier New" size="2">public ref class Matrix sealed {</font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>float *m_mat;</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><o:p><font face="Courier New" size="2">&nbsp;</font></o:p></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Courier New" size="2">public:</font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>property interior_ptr&lt;float*&gt; Mat</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>{ </font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>interior_ptr&lt;float*&gt; get(){ return &amp;mp_mat; } </font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>}</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><o:p><font face="Courier New" size="2">&nbsp;</font></o:p></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>// …</font></font></p> <p class="codelastline" style="MARGIN: 0in 0in 12pt 0.5in"><font face="Courier New" size="2">};</font></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></p>]]></content:encoded>
    </item>
    <item>
      <title>Translation Guide between Managed Extensions and the new C++/CLI binding Available</title>
      <link>https://docs.microsoft.com/archive/blogs/slippman/translation-guide-between-managed-extensions-and-the-new-ccli-binding-available</link>
      <pubDate>Sat, 21 Aug 2004 22:27:00 GMT</pubDate>
      <dc:creator><![CDATA[slippman]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/slippman/2004/08/21/translation-guide-between-managed-extensions-and-the-new-ccli-binding-available/</guid>
      <description><![CDATA[C and C++ programmers are notorious for relying on pointer indirection, and it seems blog entries...]]></description>
      <content:encoded><![CDATA[<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">C and C++ programmers are notorious for relying on pointer indirection, and it seems blog entries are not immune to this. A translation guide attempting to exhaustively detail the differences between the original Managed Extensions for C++ (released with Visual Studio.NET) and the revised C++ binding to the CLI scheduled for Visual Studio 2005 <span style="mso-spacerun: yes">(</span>and attempting to provide some motivation behind each change) has been posted on MSDN at the following URL: </p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p>&nbsp;</o:p></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><o:p><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><a href="http://msdn.microsoft.com/visualc/default.aspx?pull=/library/en-us/dnvs05/html/TransGuide.asp">http://msdn.microsoft.com/visualc/default.aspx?pull=/library/en-us/dnvs05/html/TransGuide.asp</a></span></o:p></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial"><a href="https://mail.microsoft.com/exchweb/bin/redir.asp?URL=http://msdn.microsoft.com/visualc/default.aspx?pull=/library/en-us/dnvs05/html/TransGuide.asp" target="_blank"></a><o:p></o:p></span></p><o:p>&nbsp;</o:p></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">Although there has been considerable effort made in correcting all errors within the text, I am sadly aware that how imperfect these pieces of mine nevertheless turn out. So, on the one hand, I believe this guide will prove valuable to those needing this information. On the other hand, I also believe there are areas that (a) could have been made clearer, and (b) details that … well, that are in error. If you do use this guide and find either (a) or (b) (or some (c), (d), or (e) not itemized), please let me know, either by a comment to this entry or by a private email. </p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">Speaking of which – comments, that is. Due to the open nature of the internet, the providers of this site have found it necessary to provide a form of budget firewall – that is, they have put in place a facility to <i style="mso-bidi-font-style: normal">moderate</i> the comments. This basically means that I see each comment before it becomes public, and it requires a click of my mouse in order for it to be published. I have not – not as yet, anyway – not published a comment; however, oddly enough, I can't prove that. </p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">In any case, those of you whom have been reading this from the beginning will notice that patchwork pieces of the translation guide have been posted here in one form or another. Often, comments have helped me recognize shortcomings and recast material in a hopefully more comprehensible manner. For example, my treatment of deterministic finalization in the translation guide was considerably reworked to address some of the posted comments to the initial blog entry on that topic. As W.H.Auden said in a different context, a piece of writing is never finished, it is simply abandoned. </p>]]></content:encoded>
    </item>
    <item>
      <title>An Tour of the STL.NET</title>
      <link>https://docs.microsoft.com/archive/blogs/slippman/an-tour-of-the-stl-net</link>
      <pubDate>Sat, 14 Aug 2004 00:42:00 GMT</pubDate>
      <dc:creator><![CDATA[slippman]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/slippman/2004/08/14/an-tour-of-the-stl-net/</guid>
      <description><![CDATA[Part of the (reasonably pleasant) distractions from posting on this blog recently has been working...]]></description>
      <content:encoded><![CDATA[<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-FAMILY: Tahoma">Part of the (reasonably pleasant) distractions from posting on this blog recently has been working up the first in a series of articles on STL.NET for our Visual C++ MSDN web site. The amount of work to get from an articulation of a topic to a formal publication of it is an amazingly labor-intensive 10% -- similar to the difference between prototyping a software solution and making it deployment ready. In any case, this relatively content-free entry is just to alert you of its going on-line at <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial"><u><span style="mso-field-code: ' HYPERLINK '''"><span class="MsoHyperlink">http://msdn.microsoft.com/visualc/?pull=/library/en-us/dnvs05/html/stl-netprimer.asp?frame=true</span></span><o:p></o:p></u></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-FAMILY: Tahoma">If for some reason, this doesn't show up in the post as a clickable link, you can just visit the visual c++ subportion of the msdn site at<o:p></o:p></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-FAMILY: Tahoma"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="mso-spacerun: yes">&nbsp;</span><a href="http://msdn.microsoft.com/visualc">http://msdn.microsoft.com/visualc</a> </p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-FAMILY: Tahoma">and hopefully find a link to it there. In any case,&nbsp;the Visual C++ site, under the care and breeding of Brian Johnson and Ami Vora,&nbsp;has really been spiffed up with some very neat content and is worth a lookie-loo. <o:p></o:p></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-FAMILY: Tahoma"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-FAMILY: Tahoma">For the article, David Clark, who did a wonderful job editing the piece, asked me to come up with a summary limited to 200. I misread that as 200 words, and wrote the following. I then discovered to my chagrin that it referred to 200 characters, including white space. I thought, well, white space is without content, so if I remove that, I get perhaps another 75 characters to play with, but that doesn't actually work … In any case, here is the summary that had to be sliced mercilessly:<o:p></o:p></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-FAMILY: Tahoma"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><b style="mso-bidi-font-weight: normal"><span style="FONT-FAMILY: Tahoma">For the experienced programmer, the hardest part of moving to a new development platform such as .NET is often the absence of familiar tools through which she has honed her skills and on which she depends. For the experienced C++ programmer, one such essential toolkit is the Standard Template Library (STL), and its absence under .NET until now has been a significant disappointment. With Visual C++ 2005, we fix that by providing an STL.NET library. This article, the first in a series, provides a general overview of the STL program model using STL.NET – it discusses sequential and associative containers, the generic algorithms, and the iterator abstraction that binds the two, using plenty of program examples to illustrate each point. It begins by briefly considering the alterative container models available to the .NET programmer using C++ -- the existing System::Collections library, the new System::Collections::Generic library, and, of course, STL.NET. To provide for the widest readership, this article does not require familiarity with the STL library; however, it does presume some experience with the C++ programming language.<o:p></o:p></span></b></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><i style="mso-bidi-font-style: normal"><span style="FONT-FAMILY: Tahoma"><o:p>&nbsp;</o:p></span></i></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-FAMILY: Tahoma">This summary, when reduced to 200 characters, plus the white space i threw back in, ended as follows:</span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-FAMILY: Tahoma"></span>&nbsp;</p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-FAMILY: Tahoma"><strong>With Visual C++ 2005, the Standard Template Library (STL) has been re-engineered to work under the .NET Framework. This article, the first in a series, provides a general tour of STL.NET.</strong></span></p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-FAMILY: Tahoma"></span>&nbsp;</p> <p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-FAMILY: Tahoma">Talk about a poor relative. In any case, t</span><span style="FONT-FAMILY: Tahoma">his article is culled from a text I am writing on the C++ binding to the CLI, so if you have any concerns or comments or a content wish-list, please drop me a line. <o:p></o:p></span></p>]]></content:encoded>
    </item>
    <item>
      <title>Why C++ Supports both Class and Typename for Type Parameters</title>
      <link>https://docs.microsoft.com/archive/blogs/slippman/why-c-supports-both-class-and-typename-for-type-parameters</link>
      <pubDate>Wed, 11 Aug 2004 09:32:00 GMT</pubDate>
      <dc:creator><![CDATA[slippman]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/slippman/2004/08/11/why-c-supports-both-class-and-typename-for-type-parameters/</guid>
      <description><![CDATA[Recently, someone asked me why we support both class and typename within C++ to indicate a type...]]></description>
      <content:encoded><![CDATA[<span style="FONT-SIZE: 12pt"><font face="Palatino"> <p class="textnoindent" style="MARGIN: 6pt 0in"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma">Recently, someone asked me why we support both class and typename within C++ to indicate a type parameter since the keywords do not hold any platform significance – for example, </span><span style="FONT-SIZE: 11pt; FONT-FAMILY: Tahoma">class</span><span style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma"> is not meant to suggest a native type nor is typename meant to suggest a </span><i style="mso-bidi-font-style: normal"><span style="FONT-SIZE: 11pt; FONT-FAMILY: Tahoma">CLI</span></i><span style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma"> type. Rather, both equivalently indicate that the name following represents a parameterized type placeholder that will be replaced by a user-specfied actual type. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></span></p> <p class="text" style="MARGIN: 6pt 0in"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma">The reason for the two keywords is historical. In the original template specification, Stroustrup reused the existing class keyword to specify a type parameter rather than introduce a new keyword that might of course break existing programs. It wasn't that a new keyword wasn't considered -- just that it wasn't considered necessary given its potential disruption. And up until the ISO-C++ standard, this was the only way to declare a type parameter. <o:p></o:p></span></p> <p class="text" style="MARGIN: 6pt 0in"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma">Reuses of existing keywords seems to always sow confusion. What we found is that beginners were whether the use of the class constrained or limited the type arguments a user could specify to be class types rather than, say, a built-in or pointer type. So, there was some feeling that not having introduced a new keyword was a mistake.<o:p></o:p></span></p> <p class="text" style="MARGIN: 6pt 0in"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma">During standardization, certain constructs were discovered within a template definition that resolved to expressions although they were meant to indicate declarations. For example,<o:p></o:p></span></p> <p class="codefirstline" style="MARGIN: 6pt 0in 0pt 0.5in"><font face="Courier New" size="2">template &lt;class T&gt;</font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Courier New" size="2">class Demonstration {</font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Courier New" size="2">public:</font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Courier New" size="2">void method() {</font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>T::A *aObj; // oops …</font></font></p> <p class="code" style="MARGIN: 0in 0in 0pt 0.5in"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </span>// …</font></font></p> <p class="codelastline" style="MARGIN: 0in 0in 12pt 0.5in"><font face="Courier New" size="2">};</font></p> <p class="text" style="MARGIN: 6pt 0in"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma">While the statement containing aObj is intended by the programmer to be interpreted as the declaration of a pointer to a nested type A within the type parameter T, the language grammar interprets it as an arithmetic expression multiplying the static member A of type T with aObj and throwing away the result. Isn't that annoying! (This sort of dilemna is not possible within generics – there is no way to safely verify that any T contains an A so that the runtime can safely construct an instance of the generic type.)<o:p></o:p></span></p> <p class="text" style="MARGIN: 6pt 0in"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma">The committee decided that a new keyword was just the ticket to get the compiler off its unfortunate obsession with expressions. The new keyword was the self-describing typename. When applied to a statement, such as,<o:p></o:p></span></p> <p class="codeoneline" style="MARGIN: 6pt 0in 6pt 0.5in"><font face="Courier New" size="2">typename T::A* a6; // <i>declare pointer to </i>T<i>’s </i>A</font></p> <p class="textnoindent" style="MARGIN: 6pt 0in"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt">it instructs the compiler to treat the subsequent statement as a declaration. Since the keyword was on the payroll, heck, why not fix the confusion caused by the original decision to reuse the class keyword. Of course, given the extensive body of existing code and books and articles and talks and postings using the class keyword, they chose to also retain support for that use of the keyword as well. So that's why you have both. <o:p></o:p></span></p> <p class="textnoindent" style="MARGIN: 6pt 0in"></font></span></p>]]></content:encoded>
    </item>
    <item>
      <title>Why C++/CLI Supports both Templates for CLI Types and the CLI Generic Mechanism</title>
      <link>https://docs.microsoft.com/archive/blogs/slippman/why-ccli-supports-both-templates-for-cli-types-and-the-cli-generic-mechanism</link>
      <pubDate>Thu, 05 Aug 2004 21:27:00 GMT</pubDate>
      <dc:creator><![CDATA[slippman]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/slippman/2004/08/05/why-ccli-supports-both-templates-for-cli-types-and-the-cli-generic-mechanism/</guid>
      <description><![CDATA[I've been recently puzzling out a strategy for presenting the two mechanisms supporting...]]></description>
      <content:encoded><![CDATA[<P class=textnoindent style="MARGIN: 6pt 0in"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma">I've been recently puzzling out a strategy for presenting the two mechanisms supporting parameterized types available to the C++/CLI<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>programmer: she can use either the template mechanism adapted for use with CLI types, or the CLI generic mechanism. This is not unique to the support of parameterized types, of course, but it seems a lightening rod for pernicky questions: <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>
<P class=text style="MARGIN: 6pt 0in"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt">(1) isn't the support for two mechanisms that are similar in intent but which differ in both gross and subtle semantic behavior confusing for a user? <o:p></o:p></SPAN></P>
<P class=text style="MARGIN: 6pt 0in"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt">(2) doesn't the dual nature of these constructs increase the liklihood of programmer error? <o:p></o:p></SPAN></P>
<P class=text style="MARGIN: 6pt 0in"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt">(3) isn't this a canonical illustration of the undisciplined nature of the C++ language design where everything but the kitchen sink seems to get thrown in? you guys just can't get your act together, can you?<o:p></o:p></SPAN></P>
<P class=text style="MARGIN: 6pt 0in"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt">Let's see what kind of answers I can offer. [Disclaimer: of course, these are my thoughts, and do not represent either the corporate views or policies of Microsoft.]<o:p></o:p></SPAN></P>
<P class=text style="MARGIN: 6pt 0in"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt">The C++ binding to the CLI which I refer to as C++/CLI represents an integration of two separate object models: the static object model of native C++ and the dynamic program model of the CLI. We've seen conflicts between these two models before &#8211; in particular between the native and CLI enum, the native and CLI array, and the native and CLI reference class. <o:p></o:p></SPAN></P>
<P class=text style="MARGIN: 6pt 0in"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt">Under the CLI object model, individual languages are &#8211; not to put too fine a point on it &#8211; somewhat diminished &#8211; much as how in a modern country, the individual states while soverign are constrained to the laws of the central authority. For example, the CLI defines the underlying type system within which a language operates, as well as the inheritance model. As we saw in an earlier blog, the CLI does not, for example, support private inheritance, value inheritance (that is, the inheritance of implementation but not of type), or multiple inheritance (MI). While a language can choose to support these aspects of inheritance, that support requires a mapping onto the existing CLI object model because there is no direct support. <o:p></o:p></SPAN></P>
<P class=text style="MARGIN: 6pt 0in"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt">The Eiffel language under CLI, for example, choose to provide an MI mapping because it felt that (a) MI is a valuable inheritance model, and (b) its users would be dimished without its support under the CLI &#8211; that is, it would give its users a dimished programming experience under the CLI than on native platforms, and this would likely deter them from migrating to the CLI itself &#8211; or at least of migrating to the CLI while continuing to exercise their Eiffel expertise and culture.<o:p></o:p></SPAN></P>
<P class=text style="MARGIN: 6pt 0in"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt">We did not feel the same imperative as Eiffel with regards to multiple inheritance. But we did feel that imperative towards deterministic finalization of reference types declared within a local block, and so we provided a mapping of a class destructor to a IDisposable::Dispose() method, which is the CLI pattern of reclaiming resources prior to garbage collection finalization. Similarly, we did feel the imperative towards automatic memberwise copy and initialization &#8211; as supported by a copy assignment operator and copy constructor &#8211; and so we provided a mapping. (But these mappings are constrained by the underlying CLI implementation. We could not map memberwise copy into a value class because we could not guarantee that it could be carried out in all circumstances &#8211; at least that is my understanding. I haven't myself verified that but taken it on faith.)<o:p></o:p></SPAN></P>
<P class=text style="MARGIN: 6pt 0in"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt">Again, we did this because without these mappings of essential aspects of the native C++ programming experience, we believe the C++ user would have a diminished experience of programming under the CLI than on the native platform, and that this would deter them from migrating to the CLI &#8211; or at least of migrating to the CLI while continuing to exercise their C++ expertise and culture. The template mechanism is another of the essential aspects of modern C++ programming. We believe its absence would represents a significant hole in quality of programmer life when using C++/CLI. Personally, that is my deep belief. <o:p></o:p></SPAN></P>
<P class=text style="MARGIN: 6pt 0in"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt">So, with regard to parameterized types, it felt imperative that we provide some mechanism beyond what was offerred by the System::Collections namespace. The first mechanim that naturally comes to mind to the C++ programmer, of course, is templates. But what about generics? Why couldn't C++/CLI use generics for containing the CLI types, and leave templates for the non-CLI types? Why map the template mechanism into C++/CLI to support the CLI reference class, value class, interface class, delegate, and function?<o:p></o:p></SPAN></P>
<P class=text style="MARGIN: 6pt 0in"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt">The honest answer is because we were left with no choice. One of the generic talking points in presentations, specifications, and hallway whispering, is that generics, while borrowing from C++ template, "does not suffer many of the complexities" of C++ templates. <o:p></o:p></SPAN></P>
<P class=text style="MARGIN: 6pt 0in"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt">What are considered as <I style="mso-bidi-font-style: normal">superfluous complexities</I> of C++ templates and were therefore eliminated from the generic mechanism &#8211; partial template specialization, the ability to inherit from the type parameter, support for non-type and template type parameters, the ability to specialize either an entire or selected members of a template, and so on &#8211; are considered by professional C++ programmers and designers of the language as<I style="mso-bidi-font-style: normal"> essential</I> <I style="mso-bidi-font-style: normal">modern</I> <I style="mso-bidi-font-style: normal">programming</I> <I style="mso-bidi-font-style: normal">design</I> <I style="mso-bidi-font-style: normal">patterns</I> that are fundamental to existing production code and widely-used libraries, such as the STL, LOKI, and Boost. <o:p></o:p></SPAN></P>
<P class=text style="MARGIN: 6pt 0in"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt">The real problem is that although the C++ community and language designers and implementors have deep experience with parameterized types, that experience was not tapped while the design of generics were underway. <o:p></o:p></SPAN></P>
<P class=text style="MARGIN: 6pt 0in"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt">So, we did not have any choice but to provide support of templates for CLI types and to provide an STL.NET implementation. This is great stuff if you care about C++ and want to see it succeed under .NET. Except for performance issues, C++/CLI, in my biased opinion, is shaping up as the premier C++ experience available. Personally, I'm so keen on the new language that I'm planning to reimplement my mscfront translator into the C++/CLI code from native. I'll be reporting my progress on that in quite some detail in a series of blog entries once I get the C++/CLI text I'm working on in shape. <SPAN style="mso-spacerun: yes">&nbsp;</SPAN><o:p></o:p></SPAN></P>
<P class=text style="MARGIN: 6pt 0in"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt">So, that's why we have templates. Why did we also provide support for generics? Generics are deeply integrated into the CLI, and for that reason solve a number of problems left unsolved in C++ &#8211; in particular, the instantiation model. Because there is no concept of a runtime within native C++, there is no native concept of how a template is instantiated<A title="" style="mso-footnote-id: ftn1" HREF="/slippman/admin/EditPosts.aspx#_ftn1" name=_ftnref1><SPAN class=MsoFootnoteReference><SPAN style="mso-special-character: footnote"><SPAN class=MsoFootnoteReference><SPAN style="FONT-SIZE: 12pt; COLOR: black; FONT-FAMILY: Tahoma; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-no-proof: yes">[1]</SPAN></SPAN></SPAN></SPAN></A> &#8211; that is, when the binding of an actual parameter to the formal parameter occurs and to what extent. The work of the ISO committee in this area has not been stellar.<o:p></o:p></SPAN></P>
<P class=text style="MARGIN: 6pt 0in"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt">Generics provides a constraint mechanism, something whose absence is keenly felt in the template mechanism.<A title="" style="mso-footnote-id: ftn2" HREF="/slippman/admin/EditPosts.aspx#_ftn2" name=_ftnref2><SPAN class=MsoFootnoteReference><SPAN style="mso-special-character: footnote"><SPAN class=MsoFootnoteReference><SPAN style="FONT-SIZE: 12pt; COLOR: black; FONT-FAMILY: Tahoma; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-no-proof: yes">[2]</SPAN></SPAN></SPAN></SPAN></A> A generic type is recognized by the CIL &#8211; the intermediate language; a template class is not, and so template classes are not cross-language and, it turns out, not cross-assembly as well. That is to say, every serious CLI language has to provide generic support. And that is what we do. Perhaps if we had been participants in the design, the outcome could have been different. But that, to repeat my aunt's favorite refrain, is water under the bridge.<o:p></o:p></SPAN></P>
<P class=text style="MARGIN: 6pt 0in"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt">So, from my perspective, that is why we support both the template and generic solutions for parameterized types, and have tried to integrate them into a elegant symmetry. <o:p></o:p></SPAN></P>
<P class=text style="MARGIN: 6pt 0in"><SPAN style="FONT-SIZE: 12pt; mso-bidi-font-size: 10.0pt"><o:p><FONT face=Palatino>&nbsp;</FONT></o:p></SPAN></P>
<P class=textnoindent style="MARGIN: 6pt 0in"><SPAN style="FONT-SIZE: 12pt"><o:p><FONT face=Palatino>&nbsp;</FONT></o:p></SPAN></P>
<P class=text style="MARGIN: 6pt 0in"><o:p><FONT face=Palatino size=2>&nbsp;</FONT></o:p></P>
<DIV style="mso-element: footnote-list"><BR clear=all><FONT face=Palatino size=2>
<HR align=left width="33%" SIZE=1>
</FONT>
<DIV id=ftn1 style="mso-element: footnote">
<P class=MsoFootnoteText style="MARGIN: 0in 0in 0pt"><A title="" style="mso-footnote-id: ftn1" HREF="/slippman/admin/EditPosts.aspx#_ftnref1" name=_ftn1><SPAN class=MsoFootnoteReference><SPAN style="FONT-FAMILY: Palatino"><SPAN style="mso-special-character: footnote"><SPAN class=MsoFootnoteReference><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Palatino; mso-bidi-font-family: 'Times New Roman'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-no-proof: yes"><FONT face=Tahoma>[1]</FONT></SPAN></SPAN></SPAN></SPAN></SPAN></A><SPAN style="FONT-FAMILY: Palatino"><FONT size=2><FONT face=Tahoma> Not surprisingly, the vocabulary for the different aspects and actions on a parameterized types are quite different between generics and templates &#8211; and I am not going down that path.<o:p></o:p></FONT></FONT></SPAN></P></DIV>
<DIV id=ftn2 style="mso-element: footnote">
<P class=MsoFootnoteText style="MARGIN: 0in 0in 0pt"><A title="" style="mso-footnote-id: ftn2" HREF="/slippman/admin/EditPosts.aspx#_ftnref2" name=_ftn2><SPAN class=MsoFootnoteReference><SPAN style="mso-special-character: footnote"><SPAN class=MsoFootnoteReference><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-no-proof: yes"><FONT face=Tahoma>[2]</FONT></SPAN></SPAN></SPAN></SPAN></A><FONT size=2><FONT face=Tahoma> <SPAN style="FONT-FAMILY: Palatino">Bjarne's original Usenix template paper included a discussion of constraint syntax, which he then chose not to incorporate into the design. It's absence means that there is no way to know prior to actual instantiation whether a type is qualified to be used with a particular template class &#8211; other than examining the source code &#8211; which is not really practicable.<o:p></o:p></SPAN></FONT></FONT></P></DIV></DIV>]]></content:encoded>
    </item>
    <item>
      <title>Identifying the Candidate Function Set</title>
      <link>https://docs.microsoft.com/archive/blogs/slippman/identifying-the-candidate-function-set</link>
      <pubDate>Sun, 01 Aug 2004 23:58:00 GMT</pubDate>
      <dc:creator><![CDATA[slippman]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/slippman/2004/08/01/identifying-the-candidate-function-set/</guid>
      <description><![CDATA[Sorry it is taking me so long these days. I am in the throes of more formal writing &#8211; a book...]]></description>
      <content:encoded><![CDATA[<P class=textnoindent style="MARGIN: 6pt 0in"><FONT face=Arial>Sorry it is taking me so long these days. I am in the throes of more formal writing &#8211; a book on our CLI binding for C++, and a series of articles for our Visual C++ MSDN website on STL.NET. And my translation tool is happily going through a formal test cycle &#8211; thank you Mitchell and Arjun &#8211; and so I've been fixing bugs and being a developer once more again. So the blog gets bogged down.</FONT></P>
<P class=text style="MARGIN: 6pt 0in"><FONT face=Arial>I thought I would follow up on the issue of overload function resolution. And so this entry discusses how a candidate function list is built up. (I realize this is somewhat esoteric, but. Well, I hope someone finds it worth a spin around the page.)</FONT></P>
<P class=text style="MARGIN: 6pt 0in"><FONT face=Arial>The first question of course, is, <I style="mso-bidi-font-style: normal">what the heck is a candidate function list</I>? Literally, a candidate function list is the set of functions sharing the same name visible at a call point. As we'll see, the complexity, when present, has to do with determining the actual set of visible functions.</FONT></P>
<P class=text style="MARGIN: 6pt 0in"><FONT face=Arial>It's always good to begin with a simple example &#8211; hopefully, if we can master this one, our confidence will surge, and we can march on to the question of namespace, qualified type names in the signature of a function, and the using declaration in general. Here is our example,</FONT></P>
<P class=codefirstline style="MARGIN: 6pt 0in 0pt 1in"><FONT face="Courier New" size=2>void f(); // (1)</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 1in"><FONT face="Courier New" size=2>void f( String^ ); // (2)</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 1in"><FONT face="Courier New" size=2>void f( const string&amp; ); // (3)</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 1in"><FONT face="Courier New" size=2>void f( String^, array&lt;String^&gt;^ ); // (4)</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 1in"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p><FONT face="Courier New" size=2>&nbsp;</FONT></o:p></P>
<P class=code style="MARGIN: 0in 0in 0pt 1in"><FONT face="Courier New" size=2>int main( array&lt;String^&gt; ^args ) </FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 1in"><FONT face="Courier New" size=2>{</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 1in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>if ( args == nullptr ) </FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 1in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>handle_invalid_command_line();</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 1in"><o:p><FONT face="Courier New" size=2>&nbsp;</FONT></o:p></P>
<P class=code style="MARGIN: 0in 0in 0pt 1in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>for each ( String^ s in args )</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 1in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>f( s );</FONT></FONT></P>
<P class=codelastline style="MARGIN: 0in 0in 12pt 1in"><FONT face="Courier New" size=2>}</FONT></P>
<P class=text style="MARGIN: 6pt 0in"><FONT face=Arial>There are four candidate functions to the call of <SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">f()</SPAN> within <SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">main()</SPAN>. By inspection, we can see that only two of them are <I style="mso-bidi-font-style: normal">viable</I> &#8211; that is, only the <I style="mso-bidi-font-style: normal">(2)</I> and <I style="mso-bidi-font-style: normal">(3)</I> instances can match the actual invocation. (And <I style="mso-bidi-font-style: normal">(2)</I> is the <I style="mso-bidi-font-style: normal">best</I> viable function.)</FONT></P>
<P class=text style="MARGIN: 6pt 0in"><FONT face=Arial>So that was simple. Things start getting somewhat more complicated if the type of a function argument is declared within a namespace. Let's first look at a fully qualified name. In this case, the functions within the namespace that have the same name as the called function are added to the set of candidate func&shy;tions. For example:</FONT></P>
<P class=codefirstline style="MARGIN: 6pt 0in 0pt 0.5in"><FONT face="Courier New" size=2>namespace CLITypes </FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New">{<SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: 0.5in"><FONT face="Courier New" size=2>public ref class C {&#8230;};</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: 0.5in"><FONT face="Courier New" size=2>void takeC( C^ );</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT face="Courier New" size=2>}</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><o:p><FONT face="Courier New" size=2>&nbsp;</FONT></o:p></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT face="Courier New" size=2>// &#8230; </FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><o:p><FONT face="Courier New" size=2>&nbsp;</FONT></o:p></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT face="Courier New" size=2>void f( CLITypes::C^ cobj )</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New">{<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>// ok: calls CLITypes::takeC( C^ ) </FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>takeC( cobj ); </FONT></FONT></P>
<P class=codelastline style="MARGIN: 0in 0in 12pt 0.5in"><FONT face="Courier New" size=2>}</FONT></P>
<P class=text style="MARGIN: 6pt 0in"><FONT face=Arial>There is no <SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">takeC()</SPAN> function declared within the global scope in which <SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">f() </SPAN>is defined. There is, as well, no using declaration opening up a namespace. So, on first glance, this appears to be an illegal invocation: the candidate set appears to be empty.</FONT></P>
<P class=text style="MARGIN: 6pt 0in"><FONT face=Arial>However, because the argument is qualified to occur within the <I style="mso-bidi-font-style: normal">CLITypes</I> namespace, the functions declared within that namespace are considered as well. That is, the full set of candidate functions under this circumstance represents the union of the functions visible at the point of call and the functions declared within the namespaces of the argument types.</FONT></P>
<P class=text style="MARGIN: 6pt 0in"><FONT face=Arial>There are three general cases in which functions with the same name do not overload &#8211; at least currently. (There is some activity within the ECMA committee that hasn't jelled as yet one way or another &#8211; at least as far as I'm aware.) </FONT></P>
<P class=text style="MARGIN: 6pt 0in 6pt 0.8in; TEXT-INDENT: -0.25in; tab-stops: list .8in; mso-list: l0 level1 lfo1"><FONT face=Arial><SPAN style="mso-bidi-font-family: Palatino; mso-fareast-font-family: Palatino"><SPAN style="mso-list: Ignore">1.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN>A derived class function that reuses the name of a base class virtual function <I style="mso-bidi-font-style: normal">overrides</I> rather than overloads the base class instance. Except when the <SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">new</SPAN> slot modifier is applied, the derived class instance must conform to the signature of the base class function. It substitutes for the base class instance within the derived class virtual table. </FONT></P>
<P class=text style="MARGIN: 6pt 0in 6pt 0.8in; TEXT-INDENT: -0.25in; tab-stops: list .8in; mso-list: l0 level1 lfo1"><FONT face=Arial><SPAN style="mso-bidi-font-family: Palatino; mso-fareast-font-family: Palatino"><SPAN style="mso-list: Ignore">2.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN>A derived class function that reuses the name of a non-virtual base class function <I style="mso-bidi-font-style: normal">hides</I> rather than overloads the base class instance. The signatures of the base and derived class instance are not considered. This is because the overload candidate set for a function does not extend across scope boundaries. (This is the guy currently under siege, I believe.)</FONT></P>
<P class=text style="MARGIN: 6pt 0in 6pt 0.8in; TEXT-INDENT: -0.25in; tab-stops: list .8in; mso-list: l0 level1 lfo1"><FONT face=Arial><SPAN style="mso-bidi-font-family: Palatino; mso-fareast-font-family: Palatino"><SPAN style="mso-list: Ignore">3.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN>A function declared within a local block hides rather than overloads all named instances of that function within the enclosing scopes for the extent of that block. This is the most esoteric of the three cases, so let me provide a quick example,</FONT></P>
<P class=codefirstline style="MARGIN: 6pt 0in 0pt 0.8in"><FONT face="Courier New" size=2>String^ <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:place w:st="on"><st1:City w:st="on">Marshall</st1:City></st1:place>( int ); // (1)</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.8in"><FONT face="Courier New" size=2>String^ g() {</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.8in"><FONT face="Courier New" size=2>{</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.8in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>// these puppies hide global instance &#8230;</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.8in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>String^ <st1:place w:st="on"><st1:City w:st="on">Marshall</st1:City></st1:place>( double ); // (2)</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.8in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>String^ <st1:place w:st="on"><st1:City w:st="on">Marshall</st1:City></st1:place>( char* );<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>// (3)</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.8in"><o:p><FONT face="Courier New" size=2>&nbsp;</FONT></o:p></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.8in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>return <st1:place w:st="on"><st1:City w:st="on">Marshall</st1:City></st1:place>( 1024 ); // resolves to (2)</FONT></FONT></P>
<P class=codelastline style="MARGIN: 0in 0in 12pt 0.8in"><FONT face="Courier New" size=2>}</FONT></P>
<P class=text style="MARGIN: 6pt 0in"><FONT face=Arial>In this example, the global instance of <st1:place w:st="on"><st1:City w:st="on"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">Marshall</SPAN></st1:City></st1:place><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">()</SPAN> is not visible within <SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">g()</SPAN>; the candidate functions are limited to the two declarations within <SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">g()</SPAN> itself. The <SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">char*</SPAN> instance is not a viable candidate function for an actual argument of <SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">1024</SPAN>. This leaves us with instance (2) match the formal parameter of type <SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">double</SPAN> through a standard conversion although the global instance, if considered, represents an exact match.</FONT></P>
<P class=text style="MARGIN: 6pt 0in"><FONT face=Arial>The candidate functions also depend on the visibility of <I style="mso-bidi-font-style: normal">using</I> declarations at the call point. This is because a using declaration opens up a namespace. For example, </FONT></P>
<P class=codefirstline style="MARGIN: 6pt 0in 0pt 0.5in"><FONT face="Courier New" size=2>namespace libs_R_us {</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>int max( int, int );</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>double max( double, double );</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT face="Courier New" size=2>}</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><o:p><FONT face="Courier New" size=2>&nbsp;</FONT></o:p></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT face="Courier New" size=2>char max( char, char );</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT face="Courier New" size=2>void func()</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT face="Courier New" size=2>{</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>// namespace functions not visible</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>// the three calls resolve to global max( char, char )</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><o:p><FONT face="Courier New" size=2>&nbsp;</FONT></o:p></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>max( 4096, 8192 );</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>max( 35.1, 35.9 );</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>max( 'J', 'L' );</FONT></FONT></P>
<P class=codelastline style="MARGIN: 0in 0in 12pt 0.5in"><FONT face="Courier New" size=2>}</FONT></P>
<P class=text style="MARGIN: 6pt 0in"><FONT face=Arial>In this case, the only function visible is the function declared in global scope. It is therefore the only candidate function, and is the instance invoked by all three calls within <SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">func()</SPAN>. This results the loss of precision in both arithmetic invocations. We have two choices for correcting this, both of which make use of a using directive to open the namespace. The question is where we should place it. </FONT></P>
<P class=text style="MARGIN: 6pt 0in"><FONT face=Arial>One possibility is to place using declaration in global scope. For example,</FONT></P>
<P class=codefirstline style="MARGIN: 6pt 0in 0pt 0.5in"><FONT face="Courier New" size=2>char max( char, char );</FONT></P>
<P class=codelastline style="MARGIN: 0in 0in 12pt 0.5in"><FONT face="Courier New" size=2>using libs_R_us::max; // using declaration</FONT></P>
<P class=text style="MARGIN: 6pt 0in"><FONT face=Arial>All three instances of <SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">max()</SPAN> are now visible within the global scope and are placed in the set of candidate functions. The three invocations are now each an exact match to a separate instance, as follows,</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT face="Courier New" size=2>void func()</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT face="Courier New" size=2>{</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>max( 4096, 8192 ); // libs_R_us::max(int,int);</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>max( 35.1, 35.9);<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>// libs_R_us::max(double,double);</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>max( 'J', 'L' );<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>// ::max( char, char );</FONT></FONT></P>
<P class=codelastline style="MARGIN: 0in 0in 12pt 0.5in"><FONT face="Courier New" size=2>}</FONT></P>
<P class=text style="MARGIN: 6pt 0in"><FONT face=Arial>Alternatively, we might choose to place the <I style="mso-bidi-font-style: normal">using</I> <I style="mso-bidi-font-style: normal">declaration</I> within the local scope of <SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">func()</SPAN>. Why would we do that? Primarily to limit the extent of the changes in our program due to the larger set of candidate functions. By adding to the candidate function set at global scope within an existing program, we are potentially changing the function invoked at each call point that does not involve an exact match. This may be a more invasive change than what we are ready to support. The alternative declaration looks as follows,</FONT></P>
<P class=codefirstline style="MARGIN: 6pt 0in 0pt 0.5in"><FONT face="Courier New" size=2>void func()</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT face="Courier New" size=2>{</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>// local using declaration</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>using libs_R_us::max;</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><o:p><FONT face="Courier New" size=2>&nbsp;</FONT></o:p></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>// same function calls as above</FONT></FONT></P>
<P class=codelastline style="MARGIN: 0in 0in 12pt 0.5in"><FONT face="Courier New" size=2>}</FONT></P>
<P class=text style="MARGIN: 6pt 0in"><FONT face=Arial>Surprisingly, we get a different the set of candidate functions now. This is because <I style="mso-bidi-font-style: normal">using</I> <I style="mso-bidi-font-style: normal">declara&shy;tions</I> nest.</FONT><A title="" style="mso-footnote-id: ftn1" href="/slippman/admin/EditPosts.aspx#_ftn1" name=_ftnref1><SPAN class=MsoFootnoteReference><SPAN style="mso-special-character: footnote"><SPAN class=MsoFootnoteReference><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Palatino; mso-bidi-font-family: 'Times New Roman'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"><FONT face=Arial>[1]</FONT></SPAN></SPAN></SPAN></SPAN></A><FONT face=Arial> With the <I style="mso-bidi-font-style: normal">using</I> <I style="mso-bidi-font-style: normal">declaration</I> in local scope, the global function is now hidden. The only visible functions at the call points are the two declared within the namespace, and so our character comparison resolves to the namespace instance <SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">max(int,int)</SPAN> through a promotion of the two character arguments.</FONT></P>
<P class=text style="MARGIN: 6pt 0in"><FONT face=Arial>There are two possible solutions to getting the three functions into the candidate set. We originally choose a nested <I style="mso-bidi-font-style: normal">using</I> <I style="mso-bidi-font-style: normal">declaration</I> in order to localize the inclusion of the functions to just the call points within <SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">func()</SPAN>. One solution, of course, is to move it back to global scope. But this opens the entire assembly to potential change. Alternatively, we can add the global instance to our nested set of declarations,</FONT></P>
<P class=codefirstline style="MARGIN: 6pt 0in 0pt 0.5in"><FONT face="Courier New" size=2>void func()</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT face="Courier New" size=2>{</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>// now we have all three in the candidate set</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>using libs_R_us::max;</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>extern char max( char, char );</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><o:p><FONT face="Courier New" size=2>&nbsp;</FONT></o:p></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>// same function calls as above</FONT></FONT></P>
<P class=codelastline style="MARGIN: 0in 0in 12pt 0.5in"><FONT face="Courier New" size=2>}</FONT></P>
<P class=text style="MARGIN: 6pt 0in"><FONT face=Arial>The set of candidate functions are therefore the union of the functions visible at the point of the call &#8212; including the functions introduced by <I style="mso-bidi-font-style: normal">using</I> <I style="mso-bidi-font-style: normal">declarations</I> and <I style="mso-bidi-font-style: normal">using</I> <I style="mso-bidi-font-style: normal">directives</I> &#8212; and the member functions declared in the namespaces associated with the types of the arguments. For example,</FONT></P>
<P class=codefirstline style="MARGIN: 6pt 0in 0pt 0.5in"><FONT face="Courier New" size=2>namespace basicLib {</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>void print( String^ );</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>void print( Object^ );</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT face="Courier New" size=2>}</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><o:p><FONT face="Courier New" size=2>&nbsp;</FONT></o:p></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT face="Courier New" size=2>namespace matrixLib {</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>public ref class Matrix { /* ... */ };</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>void print( Matrix^ );</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT face="Courier New" size=2>}</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><o:p><FONT face="Courier New" size=2>&nbsp;</FONT></o:p></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT face="Courier New" size=2>void display()</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT face="Courier New" size=2>{</FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>using basicLib::print;</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>matrixLib::Matrix ^mObj;</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><o:p><FONT face="Courier New" size=2>&nbsp;</FONT></o:p></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>print( mObj );<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>// matrixLib::print( Matrix^ )</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>print( "literal" ); // basicLib::print( String^ )</FONT></FONT></P>
<P class=code style="MARGIN: 0in 0in 0pt 0.5in"><FONT size=2><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>print( 1024 );<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>// basicLib::print( Object^ )</FONT></FONT></P>
<P class=codelastline style="MARGIN: 0in 0in 12pt 0.5in"><FONT face="Courier New" size=2>}</FONT></P>
<P class=text style="MARGIN: 6pt 0in"><FONT face=Arial>Which functions are the candidate functions for the call <SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">print(mObj)</SPAN>? The two <SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">basicLib</SPAN> functions introduced by the local <I style="mso-bidi-font-style: normal">using</I> <I style="mso-bidi-font-style: normal">declaration</I> are candidate functions because they are visible at the point of the call. Because the function call argument is of type <SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">matrixLib::Matrix</SPAN>, the <SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">print()</SPAN> function declared within the namespace <SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">matrixLib</SPAN> is also a candidate func&shy;tion. </FONT></P>
<P class=text style="MARGIN: 6pt 0in"><FONT face=Arial>Once the candidate functions are identified, the next step &#8211; which begins to involve type checking &#8211; is to determine the viable functions within the candidate set. That topic is a candidate for a subsequent blog.</FONT></P>
<DIV style="mso-element: footnote-list"><BR clear=all><FONT face=Palatino>
<HR align=left width="33%" SIZE=1>
</FONT>
<DIV id=ftn1 style="mso-element: footnote">
<P class=MsoFootnoteText style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: justify"><A title="" style="mso-footnote-id: ftn1" href="/slippman/admin/EditPosts.aspx#_ftnref1" name=_ftn1><SPAN class=MsoFootnoteReference><SPAN style="mso-special-character: footnote"><SPAN class=MsoFootnoteReference><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA">[1]</SPAN></SPAN></SPAN></SPAN></A><FONT size=2> Using directives do not nest. That is, </FONT><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'">using</SPAN><FONT size=2> </FONT><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'">libs_R_us</SPAN><FONT size=2> makes the namespace members visible <I style="mso-bidi-font-style: normal">as</I> <I style="mso-bidi-font-style: normal">if</I> they were declared outside the namespace at the location where the namespace is defined. Therefore, whether the using directive is nested or global makes no difference.</FONT></P></DIV></DIV>]]></content:encoded>
    </item>
    <item>
      <title>The Value of a Value Class</title>
      <link>https://docs.microsoft.com/archive/blogs/slippman/the-value-of-a-value-class</link>
      <pubDate>Fri, 23 Jul 2004 12:33:00 GMT</pubDate>
      <dc:creator><![CDATA[slippman]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/slippman/2004/07/23/the-value-of-a-value-class/</guid>
      <description><![CDATA[A reader questions the nature of the value type when he writes,
&nbsp;
Sender: Slawomir...]]></description>
      <content:encoded><![CDATA[<P class=MsoNormal style="MARGIN: 0in 0in 0pt">A reader questions the nature of the value type when he writes,</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p>&nbsp;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"><I style="mso-bidi-font-style: normal"><SPAN style="FONT-SIZE: 10pt">Sender: Slawomir Lisznianski<BR>=====================================<BR>1) Lack of support for SMFs makes value classes unnatural to use. An example in the C++/CLI spec at page 33 is incorrect, as it uses constructors with value classes. In fact, quite a few value class examples in the specification contradict with paragraph 21.4.1.<o:p></o:p></SPAN></I></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">SMF, for the uninitiated, means special member functions, and in this case refers to the constraint on a value class that it cannot declare a default constructor, copy constructor, copy assignment operator, or destructor. </P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">Mechanically, the reason these special member functions are not supported, I am told, is because there exists conditions during run-time in which it is not possible for the compiler to insert the appropriate invocations, and thus it is not possible to guarantee the semantics associated with these member functions. And so their support has been withdrawn completely. I suspect that the examples were written before the withdrawal of the default constructor, and the authors of the spec simply overlooked removing them.</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">There are a number of negative responses one can have to this: Disbelief, disgust, savage anger are a few that come to mind. </P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">Another way of looking at this is to consider the why and when these special member functions are not required. <SPAN style="mso-spacerun: yes">&nbsp;</SPAN>We do not need a copy constructor nor a copy operator when the aggregate type supports bitwise copy. Similarly, we do not need a destructor when the state of the aggregate type exhibits value semantics. Finally, if the runtime zeros out all state by default, then we do not require a default constructor. (In C++, primitive data types are not automatically zeroed out, and so most of our default constructor use &#8211; but granted, not all &#8211; is used to put the object in an uninitialized state.)</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">That is, a value type in the philosophy of the CLI unified type system is a blitable entity with no internal plumbing, so to speak. That is all it naturally supports. </P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">You put a pointer in it, you got troubles &#8211; there are no special member functions to provide deep copy semantics or to free the resource addressed prior to the end of its lifetime. Let's not even consider attempting to declare complex member types. That's not what you do with value classes.</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">I will claim that they are not unnatural. What is unnatural, but understandable presuming that you have a C++ background, are the sophisticated uses you think to put these rather unsophisticated types. When you think value class, think integer. Then things will begin to click for you.</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p>I will address your second question in a subsequent blog: <FONT size=2>So what's the rationale for trackable references ... ?</FONT><BR></o:p></P>]]></content:encoded>
    </item>
    <item>
      <title>String Literal Conversion to String: Is It a Disaster?</title>
      <link>https://docs.microsoft.com/archive/blogs/slippman/string-literal-conversion-to-string-is-it-a-disaster</link>
      <pubDate>Fri, 23 Jul 2004 08:49:00 GMT</pubDate>
      <dc:creator><![CDATA[slippman]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/slippman/2004/07/23/string-literal-conversion-to-string-is-it-a-disaster/</guid>
      <description><![CDATA[A reader asks,
&nbsp;
Sender: Jackre: String Literals are now a Trivial Conversion to StringWon't...]]></description>
      <content:encoded><![CDATA[<P class=MsoNormal style="MARGIN: 0in 0in 0pt">A reader asks,</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"><I style="mso-bidi-font-style: normal"><SPAN style="FONT-SIZE: 10pt">Sender: Jack<BR><BR>re: String Literals are now a Trivial Conversion to String<BR><BR>Won't it break most of existing libraries who will try to port to C++/CLI? One override for String^ will break a lot of user code and make calls for the overriden function with string literals look much uglier. Maybe it is better to make two types of string literals differ by, say literal prefix (i.e. old string literals would look like "this" and new ones like c"this")?<o:p></o:p></SPAN></I></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">As Adam Merz noted in his response to Jack's question of a literal modifier, </P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"><I style="mso-bidi-font-style: normal"><SPAN style="FONT-SIZE: 10pt">That is exactly what Managed Extensions for C++ did with the S prefix, and what they are trying to avoid at this point (I would think)...<o:p></o:p></SPAN></I></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"><I style="mso-bidi-font-style: normal"><SPAN style="FONT-SIZE: 10pt"><o:p>&nbsp;</o:p></SPAN></I></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">Adam is correct. Here is how I described the change in an internal translation guide between the Managed Extensions for C++ and the revised C++/CLI language &#8211; this will give you the historical context for why we made the original change.</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-ALIGN: justify"><SPAN style="FONT-SIZE: 11pt">In the original language design, a managed string literal was indicated by prefacing the string literal with an </SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">S</SPAN><SPAN style="FONT-SIZE: 11pt">. For example,<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"><SPAN style="FONT-SIZE: 11pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"><SPAN style="FONT-SIZE: 11pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">String *ps1 = "hello";<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>String *ps2 = S"goodbye";<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"><SPAN style="FONT-SIZE: 11pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-ALIGN: justify"><SPAN style="FONT-SIZE: 11pt">The performance overhead between the two initializations turns out to be non-trivial, as the following <I style="mso-bidi-font-style: normal">MSIL</I> representation demonstrates as seen through <I style="mso-bidi-font-style: normal">ildasm</I>:<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 11pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">// String *ps1 = "hello";<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">ldsflda<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>valuetype $ArrayType$0xd61117dd<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>modopt([Microsoft.VisualC]Microsoft.VisualC.IsConstModifier) <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>'?A0xbdde7aca.unnamed-global-0'<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">newobj instance void [mscorlib]System.String::.ctor(int8*)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">stloc.0<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"><SPAN style="FONT-SIZE: 10pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">// String *ps2 = S"goodbye";<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">ldstr<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>"goodbye"<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">stloc.0<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-ALIGN: justify"><SPAN style="FONT-SIZE: 11pt">That&#8217;s a pretty remarkable savings for just remembering [or learning] to prefix a literal string with an </SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">S</SPAN><SPAN style="FONT-SIZE: 11pt">. In the revised V2 language, the handling of string literals is made transparent, determined by the context of use. The </SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">S</SPAN><SPAN style="FONT-SIZE: 11pt"> no longer needs to be specified.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"><SPAN style="FONT-SIZE: 11pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-ALIGN: justify"><SPAN style="FONT-SIZE: 11pt">What about cases in which we need to explicitly direct the compiler to one interpretation or another, as in the case of an overloaded pair of functions?<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"><SPAN style="FONT-SIZE: 11pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">void f(char*);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">void f(String^);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">f("ABC");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // by default calls f(char*)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-ALIGN: justify"><SPAN style="FONT-SIZE: 11pt">In the revised language, an explicit cast is used rather than the prefix </SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">S</SPAN><SPAN style="FONT-SIZE: 11pt">. For example,<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Lucida Console'; mso-bidi-font-family: Arial"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">f(( String^ )"ABC");&nbsp;// ok: invoked f( String^ )&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">As you can see, the revised language originally sought merely to correct a failing in the original design &#8211; the surprisingly performance penalty for a user misstep in the declaration of a CLI string literal. </P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">This subsequent refinement during the standardization of the language under ECMA represents imo a rebalancing of the CLI and native type systems -- an acknowledgement of the need for the design to be Janus-faced (an image I introduced in one of the three introductory blogs) &#8211; that is, to look equally on the needs of the CLI and native programmer. </P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">Which brings us back to Jack's original question: isn't this going to blow existing code out of the water? Or, to put it more crudely, isn't this a disaster?</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">Well, I don't believe so, although I wasn't part of the decision-making process and since the change is currently undocumented as far as I am aware, I have not seen any analysis of the effect of the language change. So, let me give you my take on the effect, and give my reasoning as to why I don't see it as being quite as dire as does Jack.</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></P>
<OL style="MARGIN-TOP: 0in" type=1>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo1">The addition of a trivial conversion of a string literal to String^ is <I style="mso-bidi-font-style: normal">equivalent</I> to that of const char* rather than taking precedence. The determination of a best viable function, therefore, results in the introduction of an ambiguity rather than to silently change the resolution (and therefore behavior) of the program. The user would then explicitly cast the invocation to the intended type; admittedly, this could be burdensome, but it is not dangerous. </LI></OL>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.25in"><o:p>&nbsp;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in">Under C#, a change in the access level of a class member silently changes the resolution of a named reference in an existing program &#8211; which may be completely unknown to the person making the change. We are not talking here of that level of semantic rupture, but merely the difficulty of accommodating the mechanical importation of native code into the CLI program space.</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"><o:p>&nbsp;</o:p></P>
<OL style="MARGIN-TOP: 0in" type=1 start=2>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo1">So, let us try to address the issue of burden, which is what I suspect this all reduces to. I don't believe it is really all that extensive because the C++ overload mechanism operates by scope rather than signature, and so the set of candidate functions is constrained &#8211; unlike a language like C#, for example, where a change like this would be, I suspect, more severe and difficult to manage. (Again, I am not part of the design process currently and so I haven't drilled down on this as deeply as I otherwise might.)</LI></OL>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.25in"><o:p>&nbsp;</o:p></P>
<OL style="MARGIN-TOP: 0in" type=1 start=2>
<OL style="MARGIN-TOP: 0in" type=a>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; tab-stops: list 1.0in; mso-list: l0 level2 lfo1">Candidate functions are limited by scope. Therefore, the extent of the effect of adding an f(String^) to an existing set of f() is limited to the scope in which it is introduced. </LI></OL></OL>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.75in"><o:p>&nbsp;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in">To be exhaustive, we would break this down into the possible scope scenarios &#8211; local function, independent class, class hierarchy, namespace, and global scope &#8211; and analyze the extent of impact within each. I have not done that, but I suspect that it is really only the global and namespace introductions that are potentially disruptive and burdensome. </P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"><o:p>&nbsp;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in">Class hierarchies are not burdensome because names do not overload across base/derived class boundaries in C++ since they maintain their own scope. Namespaces are potentially burdensome because of using declarations, and the global namespace is burdensome just because it is the global namespace. </P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.75in"><o:p>&nbsp;</o:p></P>
<OL style="MARGIN-TOP: 0in" type=1 start=2>
<OL style="MARGIN-TOP: 0in" type=a start=2>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; tab-stops: list 1.0in; mso-list: l0 level2 lfo1">the introduction of an f(String^) within a class or class hierarchy is not truly burdensome in its potential introduction of an ambiguity. While it may cause a cascade of ambiguities with the introduction of f(String^) at global scope, or within a heavily-used namespace, the real questions then is a design question, imo. What is the purpose of introducing the f(String^) in a space in which const char* is still heavily used? Perhaps in migrating the existing native code base, we should exercise some design refactoring of the interface?<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>What is the benefit of supporting both const char* and String in a CLI environment? and so on. </LI></OL></OL>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">So, I think the spirit of the change is in the right direction. The solution isn't perfect, however, since this represents the only potentially truncating trivial conversion &#8211; this is what I mean when I say that imo it is not strictly ISO-C++ conforming: there are no other trivial conversions that suffer a loss of precision &#8211; those are all more costly conversions. Of course, on the other hand, String^ is not ISO-C++, but I am not being that literal here. The problem is that if I place a wide-character in the string literal while it exactly matches String^ in the abstract, in practice, it is first parsed as a const char*, and so the second byte is discarded. <SPAN style="mso-spacerun: yes">&nbsp;</SPAN>(Thank you, Dave Waggoner, for pointing out that problem.)</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p>&nbsp;</o:p></P>]]></content:encoded>
    </item>
  </channel>
</rss>