<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">Eric Fleegal's WebLog</title><subtitle type="html">. . . . </subtitle><id>http://blogs.msdn.com/ericflee/atom.xml</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ericflee/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/ericflee/atom.xml" /><generator uri="http://communityserver.org" version="2.1.61025.2">Community Server</generator><updated>2004-07-02T18:18:00Z</updated><entry><title>Performance as a Design Consideration</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ericflee/archive/2008/10/27/performance-as-a-design-consideration.aspx" /><id>http://blogs.msdn.com/ericflee/archive/2008/10/27/performance-as-a-design-consideration.aspx</id><published>2008-10-28T09:50:00Z</published><updated>2008-10-28T09:50:00Z</updated><content type="html">&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;For many years now I've been frustrated by industry development practices that approach software performance in an ad hoc manner rather than as a design issue.&amp;nbsp; Every time I argue in favor of considering a feature’s potential performance issues up front rather than after the fact, the response is consistently one or more of the following:&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in; mso-list: l1 level1 lfo2" class=MsoNormal&gt;&lt;?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;&lt;st1:City w:st="on"&gt;&lt;st1:place w:st="on"&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;Moore&lt;/SPAN&gt;&lt;/st1:place&gt;&lt;/st1:City&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;'s law will solve most performance issues; its not worth our time&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in; mso-list: l1 level1 lfo2" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;All performance problems are bugs; find and fix them at the end&lt;BR&gt;Or, “premature optimization is the root of all evil” (Hoare’s dictum)&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in; mso-list: l1 level1 lfo2" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;The performance trade-offs are worth the gains&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;If you’re a programmer, you’ve no doubt heard these arguments before.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;They are especially engrained in the culture of commercial software development where performance need only be “good enough”; where time-to-market and new feature development take priority over all else.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;In my early career at Microsoft, I joined a team building a WYSIWYG editor designed for programming. The concept was very cool, but the performance of the early prototype was so atrocious that it was practically unusable. In early 2000, a few of us on the team suggested that we needed a fundamental redesign to address performance issues.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The immediate response from the “architects” was brutal.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;We were called myopic for not recognizing that &lt;st1:City w:st="on"&gt;&lt;st1:place w:st="on"&gt;Moore&lt;/st1:place&gt;&lt;/st1:City&gt;’s law would more efficiently solve any performance problems we could fix.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;They insisted that the performance tradeoffs of their design were worth the benefits they offered.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;And they harshly admonished us for not recognizing that performance problems are “bugs” to be discovered and dealt with at the end of a product cycle.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Naturally I left the team within weeks of that meeting.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;By the end of 2000, after a nearly a decade of very expensive research and development, the project was cancelled owing to a failure to demonstrate a usable prototype.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Performance was important after all, and while I lamented the death of a promising idea, I must admit to a little &lt;I style="mso-bidi-font-style: normal"&gt;&lt;A target=_blank href="http://en.wikipedia.org/wiki/Schadenfreude"&gt;&lt;FONT color=#800080&gt;schadenfreude&lt;/FONT&gt;&lt;/A&gt;&lt;/I&gt; over its demise.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;Customers care about performance.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;They care a lot about performance, and consequently we developers should care about it too, and we should do so from the start.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;There are critical problems with the three common arguments against an a priori approach to developing efficient software.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;Moore’s Law No Longer to the Rescue&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;In the 1990s, successful development houses typically didn’t invest much design time on performance improvements because &lt;st1:place w:st="on"&gt;&lt;st1:City w:st="on"&gt;Moore&lt;/st1:City&gt;&lt;/st1:place&gt;’s law often rendered such efforts superfluous.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;In the early 90s I was on a development team that spent months improving the performance of our software. By the time we finished, CPUs had more than doubled in speed and we lost out to competitors who had instead focused their efforts on additional features.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;That lesson was hard learned by many in the field, and it accounts for why it’s been so difficult to unlearn.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;The problem with depending on &lt;st1:City w:st="on"&gt;&lt;st1:place w:st="on"&gt;Moore&lt;/st1:place&gt;&lt;/st1:City&gt;’s law is that in recent years we’ve not seen the speed doubling effects of circuit density improvements that we saw in the nineties.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Circuit density continues to double every year and a half, or so, but the concomitant growth of CPU speed no longer seems to hold[1]. We can no longer rely on processor improvements to make up for our poor design choices. &lt;st1:City w:st="on"&gt;&lt;st1:place w:st="on"&gt;Moore&lt;/st1:place&gt;&lt;/st1:City&gt;’s law can no longer rescue us from bad design.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;Hoare’s Dictum Misconstrued&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;Tony Hoare’s dictum, “premature optimization is the root of all evil”, has become the excuse of choice for putting off optimization until the end of a product cycle.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;To many developers, the dictum has an almost scriptural quality to it, with the power to cut off debate whenever it’s quoted.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Unfortunately it’s been misconstrued.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;The dictum was popularized by Donald Knuth’s 1974 article “Structured Programming with Goto Statements”[2] in which he explored the use of structured programming to improve program readability and correctness.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Although the Böhm-Jacopini theorem had previously proven the equivalence of structured programs, in 1974 most programmers still eschewed structured methods because of perceived performance costs.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Knuth’s study showed that in most cases the benefits of readability and correctness outweigh the trivial performance gains of programming unstructured code.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;The full version of Hoare’s dictum is "forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil" and I generally agree with this.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;But 97% is not 100%, and 3% of code in a two-million line project is still about sixty thousand lines of code.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It’s virtually impossible for a team, at the end of a product cycle, to identify and fix performance problems with sixty thousand lines of code without enormous effort and extensive redesigns.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;If they instead consider efficiency during early design and throughout coding, their efforts at the end of a product cycle can be focused on more productive tasks like fixing real bugs.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Charles Cook, the redoubtable English blogger, put it most aptly:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;“A good software developer will do this automatically, having developed a feel for where performance issues will cause problems. An inexperienced developer will not bother, misguidedly believing that a bit of fine tuning at a later stage will fix any problems.” [3]&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;Put another way, small inefficiencies can really add up and are costly to fix after the fact.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;In the mid-nineties I joined an enterprise software team that had developed an excellent product that was to save the company millions of dollars.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Unfortunately its release was delayed because it was too slow on the computers already deployed in the field.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;I was hired, in part, to help identify and fix these problems.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Upper management was convinced that there was something wrong with the team.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;After a few weeks of careful analysis, it became clear that the performance problems were NOT the result of algorithmic bottlenecks, poor programming, bad programmers, nor of bad overall design.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Indeed, the code was some of the cleanest I’d ever seen, the algorithms solid and the team very competent and bright.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The performance problems were instead caused by hundreds of small coding trade-offs, consciously made by developers to improve readability or structure.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;No single trade-off was measurably bad but in aggregate they created substantial performance problems.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It took several months for the team to redesign and rework their individual feature areas to eliminate the overall performance problems.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;A Trade-Off Is Not Always A Trade-Up&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;On large projects, I’ve noticed that every feature team thinks that their ideas are essential and that their particular performance tradeoffs are well worth the overall advantages they offer.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;While it’s often true that a single design choice may have only a very small cost, in aggregate all those little tradeoffs often add up to huge performance barriers.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It’s critically important to measure the cost of each performance trade-off, not only relative to the feature itself but in the context of overall product execution speed.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;A single design choice may cost only a few thousand cycles every now and then, but a few hundred of these trade-offs can quickly compromise overall performance.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;References &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;[1] &lt;A href="http://wi-fizzle.com/compsci/cpu_speed_Page_2.png"&gt;&lt;FONT color=#800080&gt;http://wi-fizzle.com/compsci/cpu_speed_Page_2.png&lt;/FONT&gt;&lt;/A&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;[2] &lt;A href="http://pplab.snu.ac.kr/courses/adv_pl05/papers/p261-knuth.pdf"&gt;&lt;FONT color=#800080&gt;http://pplab.snu.ac.kr/courses/adv_pl05/papers/p261-knuth.pdf&lt;/FONT&gt;&lt;/A&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;[3] &lt;A href="http://www.cookcomputing.com/blog/archives/000084.html"&gt;&lt;FONT color=#800080&gt;http://www.cookcomputing.com/blog/archives/000084.html&lt;/FONT&gt;&lt;/A&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;Randall Hyde wrote an excellent article for the ACM, titled “The Fallacy of Premature Optimization”.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://www.acm.org/ubiquity/views/v7i24_fallacy.html"&gt;&lt;FONT color=#800080&gt;http://www.acm.org/ubiquity/views/v7i24_fallacy.html&lt;/FONT&gt;&lt;/A&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;I also offer the following as examples where the modern software design practice of putting off efficiency has resulted in very unhappy customers.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL style="MARGIN-TOP: 0in" type=disc&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; COLOR: #1f497d; tab-stops: list .5in; mso-list: l0 level1 lfo1" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"&gt;Early users of Outlook 2007… are voicing widespread complaints about the software's sluggish performance.&lt;BR&gt;&lt;A href="http://www.pcworld.com/printable/article/id,129886/printable.html"&gt;&lt;FONT color=#800080&gt;Slow Performance From Outlook 2007&lt;/FONT&gt;&lt;/A&gt;, PCWorld, Mar 16&lt;SUP&gt;th&lt;/SUP&gt; 2007&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; COLOR: #1f497d; tab-stops: list .5in; mso-list: l0 level1 lfo1" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"&gt;Outlook 2007 is one of the weaker applications in Office 2007. At times I get so frustrated with its slow response and idiosyncrasies that I'm tempted to uninstall it and go back to Outlook 2003.&lt;BR&gt;&lt;A href="http://www.post-gazette.com/pg/08096/870663-96.stm"&gt;&lt;FONT color=#800080&gt;Microsoft Outlook 2007 is no prize&lt;/FONT&gt;&lt;/A&gt;, Pittsburg Post-Gazzette, Apr 5&lt;SUP&gt;th&lt;/SUP&gt; 2007&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; COLOR: #1f497d; tab-stops: list .5in; mso-list: l0 level1 lfo1" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"&gt;A lot of MVPs are complaining about Outlook’s performance&lt;BR&gt;&lt;A href="http://www.computerworld.com/action/article.do?command=viewArticleBasic&amp;amp;articleId=286358"&gt;&lt;FONT color=#800080&gt;Outlook 2007 Users Critical of Slow Performance&lt;/FONT&gt;&lt;/A&gt;, &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL style="MARGIN-TOP: 0in" type=disc&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; COLOR: #1f497d; tab-stops: list .5in; mso-list: l0 level1 lfo1" class=MsoNormal&gt;&lt;st1:place w:st="on"&gt;&lt;SPAN style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"&gt;Vista&lt;/SPAN&gt;&lt;/st1:place&gt;&lt;SPAN style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"&gt; really is slow unless you throw a lot of hardware at it, &lt;BR&gt;&lt;A href="http://www.businessweek.com/technology/content/mar2007/tc20070315_101834.htm?sub=techmaven"&gt;&lt;FONT color=#800080&gt;Vista: Slow and Dangerous&lt;/FONT&gt;&lt;/A&gt;, &lt;I style="mso-bidi-font-style: normal"&gt;Business Week &lt;/I&gt;Mar 15&lt;SUP&gt;th&lt;/SUP&gt;, 2007&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; COLOR: #1f497d; tab-stops: list .5in; mso-list: l0 level1 lfo1" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"&gt;I have only one question for Bill Gates. Does he recall a book he wrote, called &lt;U&gt;Business@the Speed of Thought&lt;/U&gt;. Because the title is suggestive, and if that’s what he indeed believes in, I would like to know whether or how Microsoft’s latest operating system “&lt;st1:place w:st="on"&gt;Vista&lt;/st1:place&gt;” subscribes to this vision.&lt;BR&gt;&lt;A href="http://www.business-standard.com/india/storypage.php?autono=291397"&gt;&lt;FONT color=#800080&gt;Why is Vista so slow on uptake?&lt;/FONT&gt;&lt;/A&gt;, &lt;I style="mso-bidi-font-style: normal"&gt;Business Standard, &lt;/I&gt;July 17&lt;SUP&gt;th&lt;/SUP&gt; 2007&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; COLOR: #1f497d; tab-stops: list .5in; mso-list: l0 level1 lfo1" class=MsoNormal&gt;&lt;st1:place w:st="on"&gt;&lt;SPAN style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"&gt;Vista&lt;/SPAN&gt;&lt;/st1:place&gt;&lt;SPAN style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"&gt; is actually fairly bug free. Where it falls down is in the performance category.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;BR&gt;&lt;A href="http://www.informationweek.com/blog/main/archives/2007/11/top_5_things_mi.html"&gt;&lt;FONT color=#800080&gt;Top 5 Things Microsoft Must Fix In Windows Vista In 2008&lt;/FONT&gt;&lt;/A&gt;,&lt;BR&gt;&lt;I style="mso-bidi-font-style: normal"&gt;Information Week, &lt;/I&gt;Nov 28th 2007&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Verdana; COLOR: #1f497d; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9019792" width="1" height="1"&gt;</content><author><name>ericflee</name><uri>http://blogs.msdn.com/members/ericflee.aspx</uri></author></entry><entry><title>Simplifying C++ NULL terminated string handling</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ericflee/archive/2008/04/17/simplifying-c-null-terminated-string-handling.aspx" /><id>http://blogs.msdn.com/ericflee/archive/2008/04/17/simplifying-c-null-terminated-string-handling.aspx</id><published>2008-04-18T01:04:00Z</published><updated>2008-04-18T01:04:00Z</updated><content type="html">&lt;DIV&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&lt;EM&gt;I wrote the following short article several years ago.&amp;nbsp; I've reproduced it here&amp;nbsp;by request&lt;/EM&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT size=2&gt;Once of the curious features of the C language is its lack of an integrated string type.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Most programming languages developed in the 1960/70s included a basic string type. Strings in C, however,&amp;nbsp;are just a special case of array data and the only direct language support involves initialization of pointers and array values with string literals.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000 size=2&gt;Fortunately, the C++ standard library introduces a standardized string type, std::string.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Although its implementation is very well thought out, naïve use of std::string can fragment the heap, reduce performance and create unexpected bottlenecks.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;However, the same can be said for naïve use of strings in languages like Java and C#, where the String type is fundamental and most of the implementation details are hidden from the programmer.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;In C++ there are ways to mitigate potential performance problems. When I employ std::string, I prefer to use a memory model very similar to boost’s &lt;/FONT&gt;&lt;A href="http://www.boost.org/libs/pool/doc/interfaces/simple_segregated_storage.html"&gt;&lt;U&gt;&lt;FONT color=#800080 size=2&gt;segregated storage&lt;/FONT&gt;&lt;/U&gt;&lt;/A&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;; this reduces memory fragmentation and keeps all the string data within a sandbox.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;It’s fairly easy to do this once you know how to write a standard allocator.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;The strstream class in C++ is an efficient and elegant solution to complex string construction, and I prefer it over Java’s somewhat clumsy StringBuilder class. &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;If you prefer the printf way of formatting strings, the boost library offers an excellent type-safe alternative that’s built to work efficiently with standard stream classes.&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT size=2&gt;Systems programmers and developers of high performance applications typically use C style strings.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;There are a number of reasons for this, but chief amongst them are efficiency and interoperability.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;C strings are efficient precisely because they are simple -- they can be allocated on the stack or as part of a larger structure or in the free-store, and operations on them can be specifically tailored for maximum efficiency.&lt;SPAN&gt;&amp;nbsp; Moreover, &lt;/SPAN&gt;C strings are usually not optional when interacting with operating system APIs, drivers, low level libraries and legacy code.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;Being able to program with C strings is a fairly fundamental skill for most Microsoft developers; indeed, a good number of the coding questions we ask during technical interviews involve some sort of C string manipulation.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Being conversant with C string manipulation and the concomitant standard library functions is a point pride for many Microsoft programmers, especially with those who cut their teeth in C instead of C++.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Indeed, these C string "fanboys" are sometimes critical of those developers who prefer std::string over character arrays and raw character buffers (I am not one of them).&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;I find that the worst part of programming with C strings is the string library itself.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Take a very basic function like strcpy, for instance.&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;In the early days the length of a symbol name was limited to just a few characters, so we can forgive the designers for selecting a somewhat less than human readable name.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;When there was only one way to copy a string, the name strcpy wasn’t a bad choice.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;However today there are dozens of different variations on the string copy function name available to Visual C++ programmers.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Here are 24 of them from &amp;lt;string.h&amp;gt; and &amp;lt;mbstring.h&amp;gt;:&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;strcpy, wcscpy, _mbscpy, _tcscpy, &lt;/FONT&gt;&lt;/SPAN&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;strcpy_s, wcscpy_s, _mbscpy_s, _tcscpy_s, &lt;/FONT&gt;&lt;/SPAN&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;strncpy, wcsncpy, _mbsncpy, _tcsncpy, &lt;/FONT&gt;&lt;/SPAN&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;_strncpy_l, _wcsncpy_l, _mbsncpy_l, _tcsncpy_l, &lt;/FONT&gt;&lt;/SPAN&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;strncpy_s, wcsncpy_s, _mbsncpy_s, _tcsncpy_s, &lt;/FONT&gt;&lt;/SPAN&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT color=#000000&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;_strncpy_s_l, _wcsncpy_s_l, _mbsncpy_s_l, _tcsncpy_s_l&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt; &lt;/SPAN&gt;&lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000 size=2&gt;There are versions for four different character sets: ASCII, Mbcs, Unicode and TCHAR.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;There are safe and unsafe versions, locale specific versions, and versions with additional semantics.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Now multiply those semantic variations against the dozen or so basic string operations and you have &lt;I&gt;hundreds&lt;/I&gt; of different names to try to remember! &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;The function names in &amp;lt;strsafe.h&amp;gt; are a little more regular, but there are still dozens of names to remember.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;There are 24 of them for copying a string:&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;StringCbCopy, StringCbCopyA, StringCbCopyW,&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;StringCbCopyEx, StringCbCopyExA, StringCbCopyExW,&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;StringCbCopyN, StringCbCopyNA, StringCbCopyNW,&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;StringCbCopyNEx, StringCbCopyNExA, StringCbCopyNExW,&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;StringCchCopy, StringCchCopyA, StringCchCopyW,&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;StringCchCopyEx, StringCchCopyExA, StringCchCopyExW,&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;StringCchCopyN, StringCchCopyNA, StringCchCopyNW,&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT color=#000000&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;StringCchCopyNEx, StringCchCopyNAEx, StringCchCopyNWEx&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt; &lt;/SPAN&gt;&lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000 size=2&gt;To complicate matters, Strsafe.h is incomplete; it has neither multi-byte character support nor support for locale specific functions &lt;EM&gt;[locale specific functions have been added since the time this article was authored&lt;/EM&gt;].&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Moreover, the strsafe naming style is only available for those functions needing to prevent buffer overruns.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;String operations such as comparison and collation, which are already safe, have no implementation in this library. &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;I think there’s really only one name I should have to remember for each basic string operation.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;In this case, that name would be “Copy”—overloaded for each different semantic variation of the operation, but with a uniform scheme for parameterization and return values.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;The compiler should do all the work of figuring out which variation to use.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Since the name “Copy” is applicable to more than just strings, we should declare the name within a “Strings” namespace.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Since some variations are unsafe, we should introduce a counterpart namespace “UnsafeStrings” to make it very explicit when choosing to use an unsafe version of a string function.&lt;SPAN&gt;&amp;nbsp; We declare the &lt;/SPAN&gt;functions in a namespace instead of a class so that the library can be extensible.&amp;nbsp; This also makes factoring the implementation code into different files a little easier.&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;For an initial example, the basic safe Copy operations for each of three string types would be declared as follows:&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;namespace LibraryName&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;namespace Strings&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;errno_t Copy(char* destination, size_t destinationSize, const char* source);&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;errno_t Copy(unsigned char* destination, size_t destinationSize, const unsigned char* source);&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;errno_t Copy(wchar_t* destination, size_t destinationSize, const wchar_t* source);&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;These are the basic copy functions for ASCII, Mbcs and Unicode respectively.&amp;nbsp; Each of these overloaded versions of Copy simply dispatches to its counterpart in the standard library.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;For example, the ASCII version is:&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;inline errno_t Strings::Copy(char* destination, size_t destinationSize, const char* source)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;return ::strcpy_s(destination, destinationSize, source);&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;The counterpart unsafe Copy functions would be declared as follows:&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;namespace LibraryName&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;namespace UnsafeStrings&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;using Strings::Copy;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;errno_t Copy(char* destination, const char* source);&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;errno_t Copy(unsigned char* destination, const unsigned char* source);&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;errno_t Copy(wchar_t* destination, const Unicode::Char* source);&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;Notice that the safe versions of Copy are composited into the UnsafeStrings namespace with a using declaration.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;This is done for convenience and makes both Strings or UnsafeStrings a complete name-set.&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;The Unsafe definitions of Copy will need additional parameter checking to ensure that the function semantics are uniform with the safe versions.&lt;SPAN&gt;&amp;nbsp; In practice t&lt;/SPAN&gt;his doesn’t usually introduce much of a performance barrier since, depending on context, the compiler can often optimize away these additional parameter checks when the function gets expanded inline.&amp;nbsp;&amp;nbsp;The cost of the parameter checking is trivial compared to the cost of the copy.&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;inline errno_t UnsafeStrings::Copy(char* destination, const char* source)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;if (!destination || !source)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;return EINVAL;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;::strcpy(destination, source);&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;return 0;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;The different semantic variations take on a very regular form.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;For instance, to copy a limited number of characters we simply declare additional overloads as follows&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt;&amp;nbsp;&lt;/FONT&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;namespace LibraryName&lt;/SPAN&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/SPAN&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: 0.5in"&gt;&lt;FONT size=2&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Lucida Console'"&gt;namespace Strings&lt;/SPAN&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/SPAN&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;errno_t Copy(char* destination, size_t destinationSize, const char* source&lt;B&gt;, size_t maxCount&lt;/B&gt;);&lt;/SPAN&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;errno_t Copy(unsigned char* destination, size_t destinationSize, const unsigned char* source&lt;B&gt;, size_t maxCount&lt;/B&gt;);&lt;/SPAN&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;errno_t Copy(wchar_t* destination, size_t destinationSize, const wchar_t* source&lt;B&gt;, size_t maxCount&lt;/B&gt;);&lt;/SPAN&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/SPAN&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: 0.5in"&gt;&lt;FONT size=2&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Lucida Console'"&gt;&amp;nbsp;&lt;/SPAN&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: 0.5in"&gt;&lt;FONT size=2&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Lucida Console'"&gt;namespace UnsafeStrings&lt;/SPAN&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/SPAN&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;using Strings::Copy;&lt;/SPAN&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;errno_t Copy(char* destination, const char* source&lt;B&gt;, size_t maxCount&lt;/B&gt;);&lt;/SPAN&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;errno_t Copy(unsigned char* destination, const unsigned char* source&lt;B&gt;, size_t maxCount&lt;/B&gt;);&lt;/SPAN&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;errno_t Copy(wchar_t* destination, const wchar_t* source&lt;B&gt;, size_t maxCount&lt;/B&gt;);&lt;/SPAN&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/SPAN&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/SPAN&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT face=Verdana color=#444444 size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT size=2&gt;As with the earlier variations, the implementation of these simply dispatch to the correct counterpart function in the standard library.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Again, the unsafe versions will need a little additional code to perform some parameter checking.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt;The locale specific variations of Copy are similarly implemented.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt;It’s convenient to add safe versions of Copy specifically for arrays.&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;namespace Strings &lt;/FONT&gt;&lt;/SPAN&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;template &amp;lt;size_t TSize&amp;gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;inline errno_t Copy(char (&amp;amp;destination)[destinationSize], const char *source)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 1in; TEXT-INDENT: 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;return Copy(destination, destinationSize, source);&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;Other string operations are similarly easy to define.&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color=#000000&gt;Consider, for instance,&amp;nbsp;the 28 different name variations for functions comparing two strings:&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;strcmp, wcscmp, _mbscmp, _tcscmp,&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;_stricmp, _wcsicmp, _mbsicmp, _tcsicmp,&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;_stricmp_l, _wcsicmp_l, _mbsicmp_l, _tcsicmp_l,&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;strncmp, wcsncmp, _mbsncmp, _mbsncmp_l ,&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;_tcsnccmp, _tcsncmp, _tccmp,&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;_strnicmp, _wcsnicmp, _mbsnicmp, &lt;/FONT&gt;&lt;/SPAN&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;_strnicmp_l, _wcsnicmp_l, _mbsnicmp_l,&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;_tcsncicmp, _tcsnicmp, _tcsncicmp_l&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT size=2&gt;As with the copy functions, the compare functions have versions for four different character sets, ASCII, Mbcs, Unicode and TCHAR.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;There are locale specific versions, versions with case insensitive comparison semantics and some versions with different names but identical semantics.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000 size=2&gt;As with Strings::Copy, the string comparison operation should have only one name, Compare.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;The declaration for the basic Compare functions are &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;namespace LibraryName&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;namespace Strings&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;int Compare(const char* string1, const char* string2);&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;int Compare(const unsigned char* string1, const unsigned char* string2);&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;int Compare(const wchar_t* string1, const wchar_t* string2);&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;namespace UnsafeStrings&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;using Strings::Compare;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 1in; TEXT-INDENT: 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;// there are no unsafe specific versions of Compare&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;Each of these overloaded versions of Compare simply dispatches to its counterpart in the standard library.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;For example:&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;inline int Strings::Compare(const char* string1, const char* string2)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;return ::strcmp(string1, string2);&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;The function strcmp and other standard string comparison functions have undefined behavior when passed bad parameters.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;This makes them unsuitable as predicate operations for sorting algorithms and ordered containers.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Historically this was done for performance reasons since parameter checking was considered “expensive” due to the extra branch operations – this defense is somewhat dubious since comparing two strings is relatively much more expensive than the parameter checking.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Accordingly,&amp;nbsp;we redefine the Compare functions with an alternate semantic—one that is well-ordered for any two string arguments, NULL or not.&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;// function Compare(a,b)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;// Compares two strings by lexicographically&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;// returns&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;//&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&amp;lt;0 when a &amp;lt; b&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;//&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;0 when a == b&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;//&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&amp;gt;0 when a &amp;gt; b&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;// except when either a or b are NULL, then&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;//&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&amp;lt;0 when a==NULL &amp;amp;&amp;amp; b!=NULL&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;//&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;0 when a==NULL &amp;amp;&amp;amp; b==NULL&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;//&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&amp;gt;0 when a!=NULL &amp;amp;&amp;amp; b==NULL&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;inline int Strings::Compare(const char* a, const char* b)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;if (!a)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;return b ? -1 : 0;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;if (!b)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;return +1;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;return ::strcmp(a, b);&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;The new added semantics are: two NULL strings are equal, and a NULL string is considered “less than” one that isn’t NULL.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;This means that if the Strings::Compare function is used in a predicate operator, the NULL strings will be sorted forward.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;The compiler can sometimes optimize away the parameter checking when the function is inlined.&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;Case insensitive comparison requires an additional tag type.&amp;nbsp; Its introduced in the following code as enumCaseInsensitive, and the tag names CaseInsensitive and CASE_INSENSITIVE.&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;namespace LibraryName&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;namespace Strings&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;enum enumCaseInsensitive { CaseInsensitive, CASE_INSENSITIVE };&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;int Compare(const char* string1, const char* string2, enumCaseInsensitive);&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;int Compare(const unsigned char* string1, const unsigned char* string2, enumCaseInsensitive);&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;int Compare(const wchar_t* string1, const wchar_t* string2, enumCaseInsensitive);&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;namespace UnsafeStrings&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;using Strings::Compare;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;As with the case sensitive version, this version of Compare simply dispatches to the appropriate counterpart in the standard library, adding the same NULL semantics as before.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;For example:&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;inline int Strings::Compare(const char a, const char b, enumIgnoreCase)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;if (!a)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;return b ? -1 : 0;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;if (!b)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;return +1;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;return ::stricmp(a,b);&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT size=2&gt;To use the case insensitive version of Compare, the calling code simply passes in the Strings::CaseInsensitive tag.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;I usually bring the identifiers “CaseInsensitive” or “CASE_INSENSITIVE” into the current namespace with a using directive.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;using Strings::CaseInsensitive;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;. . .&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT color=#000000&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;if ( Strings::Compare(name1, name2, CaseInsensitive) &amp;lt; 0 )&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Lucida Console'"&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;. . .&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;FONT color=#000000&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&lt;STRONG&gt;Conclusion&lt;/STRONG&gt;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT size=2&gt;The completed Strings library contains the following functions: Append, Collate, Compare, CompareOrdinal, Convert, Copy, Find, IsEqual, IsLessThan, IsGreaterThan, Length, PrintF/VPrintF, PrintFLength, Replace, ScanF/VScanF, and Tokenize.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;In all, this Strings library has hundreds of functions but only sixteen function names to remember.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;Incidentally, t&lt;/SPAN&gt;he similarity to the function naming convention in the C# String class is no coincidence.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8404877" width="1" height="1"&gt;</content><author><name>ericflee</name><uri>http://blogs.msdn.com/members/ericflee.aspx</uri></author></entry><entry><title>How to do Object Properties in C++ </title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ericflee/archive/2008/04/17/how-to-do-object-properties-in-c.aspx" /><id>http://blogs.msdn.com/ericflee/archive/2008/04/17/how-to-do-object-properties-in-c.aspx</id><published>2008-04-18T01:03:00Z</published><updated>2008-04-18T01:03:00Z</updated><content type="html">&lt;DIV&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000 size=3&gt;One of the many useful features of modern languages like C# are &lt;A href="http://en.wikipedia.org/wiki/Property_(programming)"&gt;&lt;FONT color=#0066a7&gt;object properties&lt;/FONT&gt;&lt;/A&gt;&lt;/FONT&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;, as they provide a higher level of encapsulation than public fields.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;The field-like syntax is far easier to read and write than traditional C++ Get&lt;I&gt;XXX&lt;/I&gt; and Set&lt;I&gt;XXX&lt;/I&gt; functions.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000 size=3&gt;&lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000 size=3&gt;It’s surprising how many people don’t know that Visual C++ has properties too.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Microsoft added property fields into C++ as a language extension back in the days when &lt;A href="http://en.wikipedia.org/wiki/Component_Object_Model"&gt;&lt;FONT color=#0066a7&gt;COM programming&lt;/FONT&gt;&lt;/A&gt;&lt;/FONT&gt;&lt;FONT color=#000000 size=3&gt; was all the rage.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;As with most C++ language extensions, the syntax is a bit clumsy; this one uses a Microsoft specific __declspec compiler directive.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;The syntax is:&lt;/FONT&gt; 
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;__declspec ( property ( get=&lt;I&gt;nameOfGetFunction&lt;/I&gt;, put=&lt;I&gt;nameOfSetFunction&lt;/I&gt; ) ) &lt;I&gt;typeExpressing propertyName&lt;/I&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000&gt;When the compiler sees a data member declared with this attribute on the right of a member-selection operator ("." or "-&amp;gt;"), it converts the operation to a get or put function, depending on whether such an expression is an l-value or an r-value. In more complicated contexts, such as "+=", a rewrite is performed by doing both get and put.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;A property can also be declared read-only or write-only by specifying only the get or put function respectively.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;I&gt;&lt;FONT color=#000000 size=3&gt;&lt;/FONT&gt;&lt;/I&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000 size=3&gt;To make life a little easier, I introduce a header file “C++ Properties.h” with the following macros:&lt;/FONT&gt; 
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;#define PROPERTY(TYPE, NAME) __declspec(property(get=Get##NAME,put=Set##NAME)) TYPE NAME&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;#define READONLY_PROPERTY(TYPE, NAME) __declspec(property(get=Get##NAME)) TYPE NAME&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;#define WRITEONLY_PROPERTY(TYPE, NAME) __declspec(property(put=Set##NAME)) TYPE NAME&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000 size=3&gt;Notice that these macros use preprocessor token pasting so that the get and put functions always map to Get&lt;I&gt;XXX &lt;/I&gt;and Set&lt;I&gt;XXX&lt;/I&gt;, where &lt;I&gt;XXX&lt;/I&gt; is the name of the property.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;This allows us to declare classes with properties in a very readable form; for example:&lt;/FONT&gt; 
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;class GamePad&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;{&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;public:&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;. . .&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;READONLY_PROPERTY(bool, IsConnected);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;bool GetIsConnected() const;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;. . .&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;};&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000 size=3&gt;While not quite as elegant as the built in property syntax in C#, it’s not a bad substitute.&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000 size=3&gt;&lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000 size=3&gt;You can declare virtual C++ properties simply by making the getter and/or setter methods virtual.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Similarly, abstract properties can be defined by using pure virtual getter and/or setter methods.&amp;nbsp; For example:&lt;/FONT&gt; 
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;class GamePad&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;{&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;public:&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;. . .&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;READONLY_PROPERTY(bool, IsConnected);&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;// virtual property&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;virtual bool GetIsConnected() const;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;&lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;READONLY_PROPERTY(float, PollingRate);&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;// abstract property&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;virtual float GetPollingRate() const = 0;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;. . .&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;};&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000 size=3&gt;Note that the const semantics for the property are determined by the getter or setter method.&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000 size=3&gt;&lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000 size=3&gt;Array semantics are also supported. The syntax is basically the same, but with an added “[]”, as follows:&lt;/FONT&gt; 
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;__declspec ( property ( get=&lt;I&gt;nameOfGetFunction&lt;/I&gt;, put=&lt;I&gt;nameOfSetFunction&lt;/I&gt; ) ) &lt;I&gt;typeExpressing propertyName&lt;/I&gt;&lt;FONT color=#ff0000&gt;[]&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000 size=3&gt;The accessor function simply needs to take an index argument.&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#000000 size=3&gt;Although we can use our existing macros for arrays, as follows&lt;/FONT&gt; 
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;class GamePad&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;{&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;public:&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;. . .&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;READONLY_PROPERTY(ButtonState, Buttons)&lt;FONT color=#ff0000&gt;[]&lt;/FONT&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;ButtonState GetButtons(size_t buttonIndex);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;. . .&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;};&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;&lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;//&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=#000000&gt;And used like:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;GamePad gamePad;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;. . .&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;ButtonState buttonState = gamepad.Buttons[3];&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000 size=3&gt;I find it somewhat less confusing to have additional macros in “C++ Properties.h”&lt;/FONT&gt; 
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;#define ARRAY_PROPERTY(TYPE, NAME) __declspec(property(get=Get##NAME,put=Set##NAME)) TYPE NAME[]&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;#define READONLY_ARRAY_PROPERTY(TYPE, NAME) __declspec(property(get=Get##NAME)) TYPE NAME[]&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;#define WRITEONLY_ARRAY_PROPERTY(TYPE, NAME) __declspec(property(put=Set##NAME)) TYPE NAME[]&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000 size=3&gt;Changing the above class into:&lt;/FONT&gt; 
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;class GamePad&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;{&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;public:&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;. . .&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;B&gt;READONLY_ARRAY_PROPERTY&lt;/B&gt;(ButtonState, Buttons);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;ButtonState GetButtons(size_t buttonIndex);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;. . .&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;};&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000 size=3&gt;The array access functions can also be multidimensional:&lt;/FONT&gt; 
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;class Picture&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;{&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;public:&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;. . .&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;READONLY_ARRAY_PROPERTY(Color, Pixels);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Color GetPixels(unsigned int x, unsigned int y);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;. . .&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;};&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;&lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;// And used like:&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;Picture picture;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;. . . &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;Color colorAt = picture.Pixels[x][y];&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000 size=3&gt;Because Properties provide a higher level of encapsulation than public fields, I often find myself exposing private fields through const properties. &lt;/FONT&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;class GamePad&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;{&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;public:&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;. . .&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;READONLY_PROPERTY(bool, IsConnected);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;bool GetIsConnected() const { return isConnected_; }&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;. . .&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;private:&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;bool isConnected_;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;};&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000 size=3&gt;Just like traditional accessor functions, this enables internal members to change the &lt;FONT face="Courier New"&gt;isConnected_&lt;/FONT&gt; state while exposing the state to the public scope as a const property.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;This pattern is so very common that I introduce an explicit property macro for it:&lt;/FONT&gt; 
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;#define READONLY_PROPERTY_RVALUE(TYPE, NAME, RVALUE_EXPR) \&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;__declspec(property(get=Get##NAME)) TYPE NAME; \&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;TYPE Get##NAME() const { return RVALUE_EXPR; }&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000 size=3&gt;For symmetry I also add the following two macros, though admittedly they’re rarely used (and many of my colleagues hate them).&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000 size=3&gt;&lt;/FONT&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;#define PROPERTY_VALUE(TYPE, NAME, RVALUE_EXPR, LVALUE_EXPR) \&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;__declspec(property(get=Get##NAME,put=Set##NAME)) TYPE NAME; \&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;TYPE Get##NAME() const { return RVALUE_EXPR; } \&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;void Set##NAME(TYPE newValue) { LVALUE_EXPR = newValue; }&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;&lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;#define WRITEONLY_PROPERTY_LVALUE(TYPE, NAME, LVALUE_EXPR) \&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;__declspec(property(put=Set##NAME)) TYPE NAME; \&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT face="Courier New" color=#000000 size=2&gt;void Set##NAME(TYPE newValue) { LVALUE_EXPR = newValue; }&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000 size=3&gt;Although it would&amp;nbsp;preferable for C++ properties to have a cleaner built-in&amp;nbsp;syntax, these macros provide enough of an abstraction to enable use of properties without sacrificing readability.&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000000 size=3&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8404867" width="1" height="1"&gt;</content><author><name>ericflee</name><uri>http://blogs.msdn.com/members/ericflee.aspx</uri></author><category term="C++ Programming" scheme="http://blogs.msdn.com/ericflee/archive/tags/C_2B002B00_+Programming/default.aspx" /></entry><entry><title>#pragma once</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ericflee/archive/2008/04/17/pragma-once.aspx" /><id>http://blogs.msdn.com/ericflee/archive/2008/04/17/pragma-once.aspx</id><published>2008-04-18T01:02:00Z</published><updated>2008-04-18T01:02:00Z</updated><content type="html">&lt;DIV&gt;
&lt;P style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri color=#000000 size=3&gt;Most C++ compilers now support the non-standard &lt;A href="http://en.wikipedia.org/wiki/Pragma_once"&gt;&lt;FONT color=#0066a7&gt;#pragma once&lt;/FONT&gt;&lt;/A&gt; compiler directive.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;This directive instructs the compiler to #include the file only once in a single compiland, and replaces the old C-style header sentinels (often called &lt;A href="http://en.wikipedia.org/wiki/Include_guard"&gt;&lt;FONT color=#0066a7&gt;#include guards&lt;/FONT&gt;&lt;/A&gt;).&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri color=#000000 size=3&gt;The central problem with preprocessor based header sentinels is that&amp;nbsp;they require the user to create a unique symbol to identify each and every header file that might be #included by a single compiland.&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;On very large projects, this burden becomes somewhat painful.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;Consider also the distinct possibility that two libraries might contain public header files with the exact same name; using the typical __FILENAME_H__ convention, its very possible to run into name collision between the two libraries.&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Some project teams attempt to avoid this problem by imposing a strict sentinel naming standard, usually including a file's path as part its sentinel name.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;I'm not fond&amp;nbsp;of this solution because if a header file needs to be moved, as occurs when refactoring a library, it requires that the header file be edited to conform to its new location.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;The #pragma once directive avoids all this nonsense entirely.&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri color=#000000 size=3&gt;A secondary problem is one of efficiency.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;The #pragma once directive allows the compiler to avoid opening and preprocessing a header file after its been seen once.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Although it is technically possible for a compiler to implement a similar mechanism when it encounters the header sentinel pattern (GCC can do this for instance), the mechanism is a bit fragile because it depends on a user following an exact coding pattern for the optimization to work correctly.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;I’ve encountered code patterns in library header files that appear to be the header-sentinel pattern, but are in fact not.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Moreover, the compiler must account for the fact that preprocessor symbols can be explicitly #undef’d.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;I much prefer the explicit directive because it states exactly the intention of the programmer -- "include this header only once".&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri color=#000000 size=3&gt;Unfortunately for users of GCC, this compiler directive has been deprecated (although it’s still supported last time I checked).&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;It’s my &lt;I&gt;personal&lt;/I&gt; opinion that this is yet another case of Gnu’s pervasive NIH syndrome (they got it bad), however the official reason is that the construct is not portable (which I admit is technically true).&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;I do not understand why the standards committee hasn’t adopted it into the ISO standard.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;It’s a trivial compiler feature to implement.&amp;nbsp; Although its not an official language feature, &lt;EM&gt;most&lt;/EM&gt; C/C++ compilers support it.&lt;/FONT&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8404862" width="1" height="1"&gt;</content><author><name>ericflee</name><uri>http://blogs.msdn.com/members/ericflee.aspx</uri></author><category term="C++ Programming" scheme="http://blogs.msdn.com/ericflee/archive/tags/C_2B002B00_+Programming/default.aspx" /></entry><entry><title>Eschew Obfuscation</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ericflee/archive/2008/04/17/eschew-obfuscation.aspx" /><id>http://blogs.msdn.com/ericflee/archive/2008/04/17/eschew-obfuscation.aspx</id><published>2008-04-18T01:01:00Z</published><updated>2008-04-18T01:01:00Z</updated><content type="html">&lt;DIV&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;While some may think that naming conventions are &lt;A href="http://en.wikipedia.org/wiki/Much_Ado_About_Nothing"&gt;&lt;FONT color=#0066a7&gt;much ado about nothing&lt;/FONT&gt;&lt;/A&gt;, no other subject of coding standards evokes as much fervent discourse. &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;When I first started programming for Windows back in college (&lt;I&gt;ca&lt;/I&gt; 1990), I was baffled that all these really bright programmers at Microsoft would use cryptic symbol names like LPCWSTR and crgpcsz (called &lt;A href="http://en.wikipedia.org/wiki/Hungarian_notation"&gt;&lt;FONT color=#0066a7&gt;Hungarian notation&lt;/FONT&gt;&lt;/A&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;).&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;In short, it’s a naming convention that incorporates a symbol’s type information into its name using a series of short prefix identifiers.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;At the time, this seemed anathema to everything I was being taught about producing readable, maintainable code.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Indeed, this notation presented a particularly difficult barrier for me when entering the world of Windows programming, and played no small part in my choosing to be a Unix developer for many years. &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;In 2000 I had the privilege of working in Microsoft Research for &lt;A href="http://en.wikipedia.org/wiki/Charles_Simonyi"&gt;&lt;FONT color=#0066a7&gt;Dr. Charles Simonyi&lt;/FONT&gt;&lt;/A&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;, the inventor of Microsoft Word and yes, the infamous Hungarian notation.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;When I asked Charles about his popular notation and why he proposed such a confusing convention, he got this amused look on his face and told me that most people had actually missed the point entirely.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;His intention, he explained, was not simply to conflate type information into the name of a symbol; rather, he wanted to free the developer from the burden of name selection, a “frustrating and time consuming task”.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;His premise was that if two programmers, using the same convention, would independently choose the same name for the same program text, then both goals of readability and write-ability have been served.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Readability, he argued, becomes a natural artifact of write-ability, and thus emphasis on the latter is rightly placed.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Although I remained skeptical, I had to admit that given the historically weak type safety of C and its lack of name encapsulation, it wasn’t difficult to understand the broad appeal of Charles’ proposal amongst early Microsoft programmers.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Indeed, to this day some developers at Microsoft adhere to Hungarian notation with near religious fervor. &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;My personal experience is that Hungarian notation tends to obfuscate rather than to illuminate; that different programmers using Hungarian do &lt;I&gt;not&lt;/I&gt; independently choose the same names for the same program text for the same reason that different programmers don’t usually choose to write algorithms in identical ways.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;There are often many ways to implement the same algorithm using different structures and types.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;To make matters worse, independent teams inevitably choose subtle style variations, further increasing confusion and inhibiting long term maintainability.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Over time even a single team’s notation will evolve such that each successive generation of code will look progressively different from legacy code.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;I recently joined a team at Microsoft with a continuous product line that’s more than twenty years old.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;This team’s codebase includes some legacy C components so old that they look entirely different than code within recent years.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;If they had instead chosen plain English words and phrases for symbol names, their old code would be just as readable as the new code (though still in C instead of C++).&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;And while I agree with Dr. Simonyi that naming a symbol with just the right words can be difficult, even frustrating at times, I think the effort pays off in more readable, maintainable code. &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;In recent years I’ve had the joy of working with increasingly more programmers from &lt;A href="http://en.wikipedia.org/wiki/Generation_Y"&gt;&lt;FONT color=#0066a7&gt;Generation Y&lt;/FONT&gt;&lt;/A&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;These brilliant “kids” cut their teeth on object oriented programming, have never had reason to use ancient editors like &lt;A href="http://en.wikipedia.org/wiki/Vi"&gt;&lt;FONT color=#0066a7&gt;vi&lt;/FONT&gt;&lt;/A&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; or &lt;A href="http://en.wikipedia.org/wiki/Emacs"&gt;&lt;FONT color=#0066a7&gt;Emacs&lt;/FONT&gt;&lt;/A&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;, nor have they ever programmed without the aid of basic semantic tools like &lt;A href="http://en.wikipedia.org/wiki/Intellisense"&gt;&lt;FONT color=#0066a7&gt;Intellisense&lt;/FONT&gt;&lt;/A&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;To them, Hungarian notation is not just an anachronism; it’s a pedantic scheme that gets in the way of their efficiency and creativity. &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;In twenty years of programming, I’ve found one thing to be universally true:&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;consistency, above all else, is crucial to writing readable, maintainable code.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Consistency between programmers on the same team as well as consistency for the same programmer from year to year. &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;Last year I proposed as simple naming convention for my team’s C++ development.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;It can be summarized quite succinctly.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;“Use consistent, meaningful English names that reflect the object described or action being taken.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Name types, functions, properties and namespaces &lt;FONT face=Verdana&gt;&lt;SPAN style="FONT-FAMILY: 'Lucida Console'"&gt;LikeThis&lt;/SPAN&gt;, variables and parameters &lt;SPAN style="FONT-FAMILY: 'Lucida Console'"&gt;likeThis&lt;/SPAN&gt;, private fields &lt;SPAN style="FONT-FAMILY: 'Lucida Console'"&gt;likeThis_&lt;/SPAN&gt; and C++ macros &lt;SPAN style="FONT-FAMILY: 'Lucida Console'"&gt;LIKE_THIS&lt;/SPAN&gt;.”&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Notice the &lt;I&gt;intentional&lt;/I&gt; similarity to the very practical naming convention for CLR development.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;However, C++ is different enough from C# to necessitate a few changes.&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;The details of my C++ naming proposal are as follows: &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#548dd4&gt;&lt;STRONG&gt;Casing Styles Defined&lt;/STRONG&gt;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;STRONG&gt;UpperCamelCase&lt;/STRONG&gt; : the first letter in the identifier and the first letter of each subsequent, concatenated word are capitalized.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;You can use UpperCamelCase for identifiers of three or more characters.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;No underscores are used.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;For example: DeviceLock, Scene, TabScene &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;STRONG&gt;camelCase&lt;/STRONG&gt; : The first letter of an identifier is lowercase and the first letter of each subsequent concatenated work is capitalized.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;No underscores are used. &lt;/FONT&gt;&lt;FONT size=2&gt;For example: deviceLock, scene, tabScene &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;STRONG&gt;UPPER_CASE&lt;/STRONG&gt; : All letters in the identifier are capitalized.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Concatenated words are separated by an underscore. &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#548dd4&gt;&lt;STRONG&gt;Type Names&lt;/STRONG&gt;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;Type names in C++ include &lt;FONT face=Verdana&gt;&lt;SPAN style="FONT-FAMILY: 'Lucida Console'"&gt;class&lt;/SPAN&gt;, &lt;SPAN style="FONT-FAMILY: 'Lucida Console'"&gt;struct&lt;/SPAN&gt; and &lt;SPAN style="FONT-FAMILY: 'Lucida Console'"&gt;interface&lt;/SPAN&gt; identifiers, &lt;SPAN style="FONT-FAMILY: 'Lucida Console'"&gt;enum&lt;/SPAN&gt; typenames, and &lt;SPAN style="FONT-FAMILY: 'Lucida Console'"&gt;typedef&lt;/SPAN&gt;s.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;In general, type names should be noun phrases, where the noun is the entity represented by the type.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;For example, Button, Stack and File each have names that identify the entity represented by the type.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Choose names that identify the entity from the developer’s perspective; names should reflect usage scenarios.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Use these guidelines:&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;UL style="MARGIN-TOP: 0in"&gt;
&lt;UL&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Use UpperCamelCase &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Use nouns, noun phrases or occasionally adjective phrases.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Do &lt;B&gt;not&lt;/B&gt; use verbs. &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Consider ending the name of a derived class with the name of the base class. &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Prefix interfaces with the letter I.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Do &lt;B&gt;not&lt;/B&gt; prefix class names with the letter C, nor structs with the letter S, nor template class names with the letter T. &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;For a class that simply implements an interface, consider ending the class with the interface name, sans the I prefix. &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Do &lt;B&gt;not&lt;/B&gt; use abbreviations, except those that are commonly recognized (Io, Ctrl etc).&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#548dd4&gt;&lt;STRONG&gt;Template parameter names&lt;/STRONG&gt;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;Template parameter names are a bit of a special case.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Choose descriptive names for template parameters, unless a single-letter name is completely self explanatory and a descriptive name would not add value (consider using the letter T in such cases). &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;UL style="MARGIN-TOP: 0in"&gt;
&lt;UL&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Use UpperCamelCase &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Prefix the parameter name with the letter T.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Although template parameter names are usually types, it’s usually important to differentiate them from non parameterized names.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Someday our integrated development environments may provide a nice method of doing this without mangling the name; say, by displaying templated name in &lt;I&gt;italics&lt;/I&gt; for instance. &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Consider indicating semantic constraints placed on a type parameter in the naming of the parameter.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;For instance, a parameter constrained to the type ISignInMessageReceiver may be called TSignInMessageReceiver.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Use nouns or noun phrases for object types and object instances and verbs for functor or function object parameters. &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Do not use abbreviations except those that are commonly recognized.&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#548dd4&gt;&lt;STRONG&gt;Enumeration value names&lt;/STRONG&gt;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;In C#, references to enumeration value names must be prefixed by the enumeration type name.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Unfortunately, C++ has no such requirement; only the value name is referenced.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;To accommodate this in our naming convention, follow these rules: &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;UL style="MARGIN-TOP: 0in"&gt;
&lt;UL&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Use camelCase &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Declare enum types within a scope appropriate to its usage &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Use nouns, noun phrases or occasionally adjective phrases.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Do &lt;B&gt;not&lt;/B&gt; use verbs. &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Do not use abbreviations except those that are commonly recognized. &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;&lt;B&gt;Optional&lt;/B&gt;: many C++ developers prefer to prefix enumeration value names with the name of the enumeration type.&lt;SPAN&gt;&amp;nbsp; &lt;BR&gt;&lt;/SPAN&gt;For instance, &lt;FONT face=Verdana&gt;&lt;SPAN style="FONT-FAMILY: 'Lucida Console'"&gt;enum&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Lucida Console'"&gt; State&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Lucida Console'"&gt; { stateIdle, stateReading, stateWriting }&lt;/SPAN&gt;.&lt;SPAN&gt;&amp;nbsp; &lt;BR&gt;&lt;/SPAN&gt;The prefix should not be an abbreviation of the enum typename.&lt;B&gt;&lt;SPAN style="FONT-FAMILY: 'Lucida Console'"&gt; &lt;/SPAN&gt;&lt;/B&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#548dd4&gt;&lt;STRONG&gt;Preprocessor symbol names.&lt;/STRONG&gt;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;Preprocessor symbols (macros) do not exist in C#, so the CLR naming convention offers little guidance.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;The C++ industry standard is to declare macros LIKE_THIS. &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;UL style="MARGIN-TOP: 0in"&gt;
&lt;UL&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Use UPPER_CASE &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;#undef temporary macro names &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Do not use abbreviations except those that are commonly recognized. &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Macro names should be at least three characters&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#548dd4&gt;&lt;STRONG&gt;Method and function names&lt;/STRONG&gt;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;Methods are actions upon an object and their names should employ verbs and verb phrases.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Do &lt;B&gt;not&lt;/B&gt; select a name that describes how the method operates; in other words, do not use implementation details for your method names. &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;UL style="MARGIN-TOP: 0in"&gt;
&lt;UL&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Use UpperCamelCase &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Use verbs or verb phrases &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Do not use implementation details in a method’s name &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Consider prefixing event handling methods with “On”, such as “OnInitialize” &lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#548dd4&gt;&lt;STRONG&gt;Field names&lt;/STRONG&gt; &lt;/FONT&gt;&lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;Although the C# naming convention proscribes exposing any fields with public or protected protection, and recommends UpperCamelCase for private fields, I have found this to be a bit clumsy to employ in C++.&lt;SPAN&gt;&amp;nbsp; Moreover, its inconsistent with C#'s variable naming rules.&amp;nbsp; Instead, I propose the following for field names.&lt;/SPAN&gt;&lt;/FONT&gt; 
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;UL style="MARGIN-TOP: 0in"&gt;
&lt;UL&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Use camelCase &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Use descriptive names, typically nouns (though function object fields may be verbs) &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Use plural names for collection fields rather than suffixing with the container type.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Ex: “names” instead of “nameList” &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Some developer prefix private class fieldnames with “m_” (as with MFC classes).&amp;nbsp;&lt;/FONT&gt;&lt;FONT size=2&gt;I personally prefer to suffix private class fieldnames with an underscore &lt;FONT face=Verdana&gt;&lt;SPAN style="FONT-FAMILY: 'Lucida Console'"&gt;likeThis_&lt;/SPAN&gt;, as&amp;nbsp;does &lt;A href="http://en.wikipedia.org/wiki/Andrei_Alexandrescu" target=_blank&gt;&lt;FONT color=#0066a7&gt;Alexandrescu&lt;/FONT&gt;&lt;/A&gt; and other&amp;nbsp;prominent C++ developer/authors.&amp;nbsp;&lt;/FONT&gt;&amp;nbsp;Perhaps someday most IDEs allow us to visually identify member field names (say, with &lt;EM&gt;italics&lt;/EM&gt; for instance) to differentiate them from other names; until then&amp;nbsp;this kind of name decoration has shown to be useful.&lt;/FONT&gt; 
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Do &lt;B&gt;not&lt;/B&gt; decorate field names with type information (as in Hungarian notation).&amp;nbsp; &lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#548dd4&gt;&lt;STRONG&gt;C++ Property Names&lt;/STRONG&gt;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;Did you know that Microsoft’s C++ has properties?&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Well it does, though the syntax is a bit clumsy.&lt;SPAN&gt;&amp;nbsp; It uses a special &lt;A href="http://msdn2.microsoft.com/en-us/library/yhfk0thd.aspx"&gt;&lt;FONT color=#0066a7&gt;__declspec&lt;/FONT&gt;&lt;/A&gt; directive. &lt;/SPAN&gt;I usually define a set of MACROs that ameliorate the clunky syntax (I will write on that more in another blog posting). &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;UL style="MARGIN-TOP: 0in"&gt;
&lt;UL&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Use UpperCamelCase &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Use nouns, noun phrases or adjectives. &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Prefix Boolean property names with Is, Can, Has etc. where it contributes to readability. &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Prefer Boolean property names with affirmative phrases (CanSeek instead of CantSeek). &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Properties imply simple value lookups or trivial computations so do &lt;B&gt;not &lt;/B&gt;use a property when non-trivial computations are involved.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Instead use a method.&lt;/FONT&gt; 
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Prefer to name the "getter" and "setter" functions with Get&lt;EM&gt;PropertyName&lt;/EM&gt; and Set&lt;EM&gt;PropertyName&lt;/EM&gt; respectively (though this is not strictly necessary).&amp;nbsp; &lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#548dd4&gt;&lt;STRONG&gt;Parameters and auto/local variable names&lt;/STRONG&gt;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 45pt; TEXT-INDENT: -0.25in; tab-stops: list 45.0pt"&gt;&lt;FONT size=2&gt;&lt;FONT face=Verdana&gt;&lt;SPAN style="FONT-FAMILY: Symbol"&gt;&lt;SPAN&gt;·&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;Use camelCase&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 45pt; TEXT-INDENT: -0.25in; tab-stops: list 45.0pt"&gt;&lt;FONT size=2&gt;&lt;FONT face=Verdana&gt;&lt;SPAN style="FONT-FAMILY: Symbol"&gt;&lt;SPAN&gt;·&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;Use descriptive names which reflect how the variable will be used&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 45pt; TEXT-INDENT: -0.25in; tab-stops: list 45.0pt"&gt;&lt;FONT size=2&gt;&lt;FONT face=Verdana&gt;&lt;SPAN style="FONT-FAMILY: Symbol"&gt;&lt;SPAN&gt;·&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;Do &lt;B&gt;not&lt;/B&gt; decorate names with type information (as in Hungarian notation)&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 45pt; TEXT-INDENT: -0.25in; tab-stops: list 45.0pt"&gt;&lt;FONT size=2&gt;&lt;FONT face=Verdana&gt;&lt;SPAN style="FONT-FAMILY: Symbol"&gt;&lt;SPAN&gt;·&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;Use nouns, noun phrases or an adjective, except for function objects&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 45pt; TEXT-INDENT: -0.25in; tab-stops: list 45.0pt"&gt;&lt;FONT size=2&gt;&lt;FONT face=Verdana&gt;&lt;SPAN style="FONT-FAMILY: Symbol"&gt;&lt;SPAN&gt;·&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;Use plural names for collection/container fields rather than suffixing with the container type.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Ex: “names” instead of “nameList”&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 45pt; TEXT-INDENT: -0.25in; tab-stops: list 45.0pt"&gt;&lt;FONT face=Verdana&gt;&lt;FONT size=2&gt;&lt;SPAN style="FONT-FAMILY: Symbol"&gt;&lt;SPAN&gt;·&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;Avoid declaring variables in the global scope; instead declare them as variables within an appropriate namespace and follow the naming convention for C++ Properties.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt 45pt; TEXT-INDENT: -0.25in; tab-stops: list 45.0pt"&gt;&lt;FONT size=2&gt;&lt;FONT face=Verdana&gt;&lt;SPAN style="FONT-FAMILY: Symbol"&gt;&lt;SPAN&gt;·&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;Do not declare a variable with the static keyword at global scope; this is a deprecated language feature.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Instead, use an anonymous namespace.&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#548dd4&gt;&lt;STRONG&gt;Namespaces&lt;/STRONG&gt;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;UL style="MARGIN-TOP: 0in"&gt;
&lt;UL&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Use UpperCamelCase &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Use nouns or noun phrases &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Do not use generic type names that might conflict with class names (eg. Element, Node, Log, Message) &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Consider using plural names where appropriate: eg. Strings instead of String &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Do not use the same name for a namespace as a type within the namespace. &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Do not place application specific namespaces within the namespace of a shared library namespace.&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT color=#548dd4&gt;&lt;STRONG&gt;Use of Acronyms&lt;/STRONG&gt;&lt;/FONT&gt; &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;Acronyms are generally proscribed, as they reduce readability especially to those programmers for whom English is a second language.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;However, an acronym may be used if it is generally recognized by your programming community and if it doesn’t reduce readability.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Examples include DB, IO, Xml, Cpu, Gpu, Html, etc. &lt;/FONT&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;&amp;nbsp; &lt;/FONT&gt;
&lt;UL style="MARGIN-TOP: 0in"&gt;
&lt;UL&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Capitalize both characters of two-character acronyms, except the first word of a camelCase identifier.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Example: DB, IO for UpperCamelCase and ioChannel for camelCase. &lt;/FONT&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; tab-stops: list .5in"&gt;&lt;FONT size=2&gt;Capitalize only the first character of acronyms with three or more characters, except the first word in a camelCase identifier.&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8404856" width="1" height="1"&gt;</content><author><name>ericflee</name><uri>http://blogs.msdn.com/members/ericflee.aspx</uri></author></entry><entry><title>The trouble with long double</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ericflee/archive/2007/09/15/the-trouble-with-long-double.aspx" /><id>http://blogs.msdn.com/ericflee/archive/2007/09/15/the-trouble-with-long-double.aspx</id><published>2007-09-16T03:54:00Z</published><updated>2007-09-16T03:54:00Z</updated><content type="html">&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;Back in ‘04 I made a prediction that 80 bit floating point values would likely be supported in some future version of the VC++ compiler (just like we did in the 16bit version of the compiler!).&amp;nbsp; Alas, it’s now ’07 and much to my disappointment this will not come to pass; so much for my foresight.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;There are a number of technical reasons for this, not the least of which is that implementing the feature requires more than just a change to the compiler.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It is my strong impression, however, that Microsoft would have solved these issues had customers more aggressively clamored for this particular feature.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;The point is now rapidly becoming moot.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;80-bit doubles seem so “last century”.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;We are approaching&amp;nbsp;the day when most new Windows systems will have FPUs that easily support the 128bit long double format.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It seems natural to expect, or rather for our customers to demand, that 128bit long double semantics be fully supported in some future version of C++. &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;So lobby away people! &lt;A href="http://msdn2.microsoft.com/en-us/visualc/aa336397.aspx"&gt;&lt;FONT color=#800080&gt;http://msdn2.microsoft.com/en-us/visualc/aa336397.aspx&lt;/FONT&gt;&lt;/A&gt; &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: Verdana; mso-fareast-theme-font: minor-latin; mso-bidi-language: EN-US; mso-ansi-language: EN-US; mso-fareast-language: EN-US"&gt;128bit long doubles would be a nice complement to the .NET 128 bit &lt;I style="mso-bidi-font-style: normal"&gt;&lt;A href="http://msdn2.microsoft.com/en-us/library/364x0z75(vs.71).aspx"&gt;&lt;FONT color=#800080&gt;decimal&lt;/FONT&gt;&lt;/A&gt;&lt;/I&gt; floating point type.&lt;/SPAN&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4935595" width="1" height="1"&gt;</content><author><name>ericflee</name><uri>http://blogs.msdn.com/members/ericflee.aspx</uri></author><category term="VC++ floating-point" scheme="http://blogs.msdn.com/ericflee/archive/tags/VC_2B002B00_+floating-point/default.aspx" /></entry><entry><title>Typesafe method of interfacing to DirectX shaders</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ericflee/archive/2006/08/10/695055.aspx" /><id>http://blogs.msdn.com/ericflee/archive/2006/08/10/695055.aspx</id><published>2006-08-11T00:59:00Z</published><updated>2006-08-11T00:59:00Z</updated><content type="html">&lt;P&gt;I thought this idea might be of interest to DirectX C++ programmers.&lt;/P&gt;
&lt;P&gt;Typesafety is perhaps the most critical feature of higher programming languages, and yet so often application programming interfaces introduce non-typesafe constructs. This is frequently the case with low-level APIs. A great example of this is DirectX’s APIs for setting GPU registers for vertex and pixel shaders. They include methods like these:&lt;/P&gt;&lt;PRE style="MARGIN-LEFT: 0.5in"&gt;D3DVOID SetVertexShaderConstantF(&lt;BR&gt;&amp;nbsp; UINT StartRegister,&lt;BR&gt;&amp;nbsp; CONST float *pConstantData,&lt;BR&gt;&amp;nbsp; DWORD Vector4fCount&lt;BR&gt;);&lt;BR&gt;&lt;BR&gt;
D3DVOID SetPixelShaderConstantF(&lt;BR&gt;&amp;nbsp; UINT StartRegister,&lt;BR&gt;&amp;nbsp; CONST float *pConstantData,&lt;BR&gt;&amp;nbsp; DWORD Vector4fCount&lt;BR&gt;);&lt;/PRE&gt;
&lt;P&gt;StartRegister specifies the base register number, pConstantData should point to the value(s) to be loaded into the registers where each register is four floats and Vector4fCount specifies the number of registers to which the API should write. &lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;This API is intentionally generic.&amp;nbsp; But&amp;nbsp;it lacks most of the type safety C++ offers. Consider the following simple cases representing aberrant uses of the API:&lt;/P&gt;&lt;PRE style="MARGIN-LEFT: 0.5in"&gt;const float fValue = 1.5f;&lt;BR&gt;const D3DVECTOR4 v4Value(1.0f, 2.0f, 3.0f, 1.0f);&lt;BR&gt;&lt;BR&gt;
// case 1&lt;BR&gt;g_piDevice-&amp;gt;SetVertexShaderConstantF(0, &amp;amp;fValue, 1);&lt;BR&gt;
// case 2&lt;BR&gt;g_piDevice-&amp;gt;SetVertexShaderConstantF(2, (float*)fValue, 4);&lt;BR style="mso-special-character: line-break"&gt;&lt;BR style="mso-special-character: line-break"&gt;
&lt;/PRE&gt;
&lt;P&gt;In case 1, the y, z and w components of vertex constant register 0 will be loaded with unintended values. In case two, the values in register 3, 4 and 5 will be overwritten with garbage values since the Vector4Count parameter is wrong. In neither of these cases will the compiler provide an error or warning that something’s wrong.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;The easiest way to add some type safety is to provide a function that is overloaded on the value to be written. For the simple cases above, we could introduce the following: &lt;/P&gt;&lt;PRE style="MARGIN-LEFT: 0.5in"&gt;inline void SetVertexShaderConstantF(UINT RegisterID, float value)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; D3DXVECTOR4 vTemp = { value, 0, 0, 0 };&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // note: on xbox, use XMVECTOR&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; g_piDevice-&amp;gt;SetVertexShaderConstantF(RegisterID, &amp;amp;vTemp, 1);&lt;BR&gt;}&lt;BR&gt;
inline void SetVertexShaderConstantF(UINT RegisterID, const D3DVECTOR4&amp;amp; value)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; g_piDevice-&amp;gt;SetVertexShaderConstantF(RegisterID, (float*)value, 1);&lt;BR&gt;}&lt;BR style="mso-special-character: line-break"&gt;&lt;BR style="mso-special-character: line-break"&gt;
&lt;/PRE&gt;
&lt;P&gt;Some compilers, like the one on Xbox 360, are able to provide additional optimizations when parameter values to inline functions are literals. To ensure that this optimization is available when using our typesafe versions, we could add a template that passes the RegisterID as a literal instead of as a variable:&lt;/P&gt;&lt;PRE style="MARGIN-LEFT: 0.5in"&gt;template &amp;lt;UINT TRegisterID&amp;gt;&lt;BR&gt;inline void SetVertexShaderConstantF(float value)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; D3DXVECTOR4 vTemp = { value, 0, 0, 0 };&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; g_piDevice-&amp;gt;SetVertexShaderConstantF(TRegisterID, &amp;amp;vTemp, 1);&lt;BR&gt;}&lt;BR&gt;&lt;BR&gt;
. . . &lt;BR&gt;&lt;BR&gt;
// used this way&lt;BR&gt;SetVertexShaderConstantF&amp;lt;0&amp;gt;(value);&lt;BR style="mso-special-character: line-break"&gt;&lt;BR style="mso-special-character: line-break"&gt;
&lt;/PRE&gt;
&lt;P&gt;If the register traits of the target GPU are known a priori, we can further refine this idea by introducing a compile time constraint on the template parameter TRegisterID. On Xbox 360, this value must be in the range 0…255. To constrain this at compile time on the xbox 360 we can use the _STATIC_ASSERT macro:&lt;/P&gt;&lt;PRE style="MARGIN-LEFT: 0.5in"&gt;template &amp;lt;UINT TRegisterID&amp;gt;&lt;BR&gt;inline void SetVertexShaderConstantF(float value)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _STATIC_ASSERT(0&amp;lt;=TRegisterID &amp;amp;&amp;amp; TRegisterID&amp;lt;=255);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; D3DXVECTOR4 vTemp = { value, 0, 0, 0 };&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; g_piDevice-&amp;gt;SetVertexShaderConstantF(TRegisterID, &amp;amp;vTemp, 1);&lt;BR&gt;}&lt;/PRE&gt;
&lt;P&gt;An error will now be generated at compile time if the programmer uses this function with a register id that is out of range. (NOTE: If static assertions are not available in your environment, you can use or build something like the boost library’s &lt;A href="http://www.boost.org/doc/html/boost_staticassert.html"&gt;BOOST_STATIC_ASSERT&lt;/A&gt;. )&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Aside from type safety, it would be nice if our interface provided a simple, typesafe way to declare all the registers needed for a particular shader. Let me show you the basic way I do this for vertex shaders:&lt;/P&gt;&lt;PRE style="MARGIN-LEFT: 0.5in"&gt;class CVertexShader&lt;BR&gt;{&lt;BR&gt;public:&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; template &amp;lt;class TDataType, UINT TRegisterID&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; class CConstant&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public:&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;inline void operator=(const TDataType&amp;amp; value)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SetVertexShaderConstantF&amp;lt;TRegisterID&amp;gt;(value);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;BR&gt;};&lt;/PRE&gt;
&lt;P&gt;Notice that sizeof(CVertexShader::CConstant) is zero. This is important because we don't want our strategy to impose any additional memory requirements. &lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Derived classes can then easily describe a typesafe program interface to a vertex shader. For example:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;PRE style="MARGIN: 0in 0in 0pt 0.5in"&gt;class CSimpleVertexShader : public CVertexShader
{
public:
	CConstant&amp;lt; XMMATRIX,0 &amp;gt; mWorld;
	CConstant&amp;lt; XMMATRIX,4 &amp;gt; mView;
	CConstant&amp;lt; XMMATRIX,8 &amp;gt; mProjection;
	CConstant&amp;lt; XMVECTOR, 12 &amp;gt; vEyePositionW;
};

. . .
// used this way
CSimpleVertexShader Simple;
. . .
Simple.mWorld = mWorld;
			&lt;/PRE&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Essentially, this provides a compile-time name binding of a particular vertex shader’s registers that is both type-safe and convenient to use.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I also enhance class CVertexShader to add run-time binding to a particular instance of a loaded or compiled vertex shader. This looks something like the following (I’ve omitted the runtime assertions and state checking for brevity):&lt;/P&gt;&lt;PRE style="MARGIN-LEFT: 0.5in"&gt;class CVertexShader&lt;BR&gt;{&lt;BR&gt;protected:&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CInterfacePtr&amp;lt;IDirect3DVertexShader9&amp;gt; m_piVertexShader;&lt;BR&gt;public:&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; IDirect3DVertexShader9* operator -&amp;gt; () { return m_piVertexShader; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; operator IDirect3DVertexShader9* () { return m_piVertexShader; }&lt;BR&gt;&lt;BR&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; HRESULT Set() { return g_piDevice-&amp;gt;SetVertexShader( m_piVertexShader ); }&lt;BR&gt;&lt;BR&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; HRESULT Load(const char* pszFilename);&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; HRESULT Load(const wchar_t* pszFilename);&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; HRESULT Compile(const char* pszCode);&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; HRESULT Compile(const wchar_t* pszCode);&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;};&lt;/PRE&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;The implementation for the concomitant CPixelShader is nearly identical. For brevity's sake I've left out the details, but I’ll be happy to post the complete code if anyone requests it. &lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=695055" width="1" height="1"&gt;</content><author><name>ericflee</name><uri>http://blogs.msdn.com/members/ericflee.aspx</uri></author></entry><entry><title>Stanley110 asks...</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ericflee/archive/2005/09/01/458951.aspx" /><id>http://blogs.msdn.com/ericflee/archive/2005/09/01/458951.aspx</id><published>2005-09-01T11:29:00Z</published><updated>2005-09-01T11:29:00Z</updated><content type="html">&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;FONT face=Verdana&gt;Sorry I haven't had time to post in quite a while.&amp;nbsp; I’ve been developing the new Xbox Live Arcade for the upcoming Xbox 360, a project that has taken considerable time and effort.&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;FONT face=Verdana&gt;Stanley110 asks:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;FONT face=Verdana&gt;A) Excel uses double precision. What benefit with respect to accuracy or precision of the calculated result is there with respect to single precision?&lt;BR&gt;&lt;BR&gt;B) Electronic calculators use single precision? Is this true?&lt;BR&gt;&lt;BR&gt;C) Aside from computer speed and things like that, is there any difference in the accuracy and precision of an aritmetic calculation when it is by double precision than by single precision.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;Short Answer to Question A: The precision benefits of double-precision over single precision are exactly as the name suggests: at least double the precision of single precision.&amp;nbsp; Accuracy is a different question altogether.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;With carefully coded algorithms, single precision can yield very accurate results; however, most users (even most computer scientists) are not trained to devise such algorithms for all but the simplest cases.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Most of the time (though not always), if you perform the same computation in double and single precision, the double precision result will usually be more accurate.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;I hate to make a blanket statement like that, so PLEASE note the qualifiers before flaming me with email :-)&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;FONT face=Verdana&gt;More info on floating point&lt;BR&gt;&lt;/FONT&gt;&lt;A href="http://en.wikipedia.org/wiki/IEEE_floating-point_standard"&gt;&lt;FONT face=Verdana&gt;http://en.wikipedia.org/wiki/IEEE_floating-point_standard&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana&gt; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;A href="http://en.wikipedia.org/wiki/Talk:Computer_numbering_formats"&gt;&lt;FONT face=Verdana&gt;http://en.wikipedia.org/wiki/Talk:Computer_numbering_formats&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;FONT face=Verdana&gt;Accuracy and precision are not the same thing&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;A href="http://en.wikipedia.org/wiki/Accuracy"&gt;&lt;FONT face=Verdana&gt;http://en.wikipedia.org/wiki/Accuracy&lt;/FONT&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Times New Roman'"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;A href="http://en.wikipedia.org/wiki/Talk:Accuracy_and_precision"&gt;&lt;FONT face=Verdana&gt;http://en.wikipedia.org/wiki/Talk:Accuracy_and_precision&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Times New Roman'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;FONT face=Verdana&gt;(yes, I am a fan of Wikipedia; its freaking brilliant!)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;FONT face=Verdana&gt;Excel uses double precision mainly because it’s what’s available on most architectures.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Moreover, &lt;I style="mso-bidi-font-style: normal"&gt;if care is taken to properly account for error&lt;/I&gt;, doubles are precise enough for many financial computations, especially the kind used by most Excel users.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;However, even simple tax or interest computations can be perturbed by the use of double precision (so be careful and check your results!)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Times New Roman'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;FONT face=Verdana&gt;Short Answer to Question B: No; well, maybe some cheap calculators given away in a box of Cap’n Crunch, but useful calculators will have at least 12 decimal digits of precision ( single prec has only about 7; log10(2^24) ).&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Most inexpensive calculators use doubles or extended precision since the chips for it are fairly inexpensive.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Really nice calculators use extended double, quad-precision or even provide decimal-floating point precision with 28 decimal digits or more of precision.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Some even use rational number systems under certain circumstances to represent numbers like 1/10, 1/3 etc.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The built in Windows calculator, for instance, provides 32 decimal digits of precision and uses rationals for certain computations.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;FONT face=Verdana&gt;Gossip: I heard a rumor that Excel may (soon?) provide computations using .NET’s decimal type.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;But I haven’t been able to confirm this.&amp;nbsp; So naturally I must spread the rumor.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Times New Roman'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;FONT face=Verdana&gt;Short Answer to C:&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;I recommend the articles above.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Keep in mind that on many systems, double precision computations are just as fast or even faster than single precision computations.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=458951" width="1" height="1"&gt;</content><author><name>ericflee</name><uri>http://blogs.msdn.com/members/ericflee.aspx</uri></author></entry><entry><title>Visual Studio 2005 Beta</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ericflee/archive/2004/12/23/331385.aspx" /><id>http://blogs.msdn.com/ericflee/archive/2004/12/23/331385.aspx</id><published>2004-12-23T19:34:00Z</published><updated>2004-12-23T19:34:00Z</updated><content type="html">&lt;p&gt;Several people have sent technical support questions to me.&amp;nbsp; I'm not ignoring you; I am interested in your comments.&amp;nbsp; However, I don't have time to answer technical support questions in my blog.&amp;nbsp; &lt;/p&gt; &lt;p&gt;I would refer readers to &lt;a href="http://lab.msdn.microsoft.com/vs2005/default.aspx"&gt;http://lab.msdn.microsoft.com/vs2005/default.aspx&lt;/a&gt;&amp;nbsp;for more information about the VS2005 beta-1 and beta-2.&lt;/p&gt; &lt;p&gt;Please post your TECHNICAL SUPPORT questions in the &lt;a href="http://communities.microsoft.com/newsgroups/default.asp?icp=whidbey&amp;amp;amp;slcid=us"&gt;community newsgroups&lt;/a&gt;.&amp;nbsp; Employees in the VS division routinely answer questions in these newsgroups.&amp;nbsp; Developers in the greater C++ community also participate in answering questions.&amp;nbsp; &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=331385" width="1" height="1"&gt;</content><author><name>ericflee</name><uri>http://blogs.msdn.com/members/ericflee.aspx</uri></author></entry><entry><title>Single Vs. Double ...</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ericflee/archive/2004/12/21/329228.aspx" /><id>http://blogs.msdn.com/ericflee/archive/2004/12/21/329228.aspx</id><published>2004-12-21T21:45:00Z</published><updated>2004-12-21T21:45:00Z</updated><content type="html">&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;It’s almost Christmas as evidenced by how dead the office is; it’s pretty common for people at Microsoft to take-off the week of Christmas, and sometimes the following week.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;MS is fairly generous with holidays, giving us both Christmas Eve and Christmas day.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;This allows people to spend only 3 vacation days for a full week’s vacation.&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;A few readers have asked if double-precision is so much better than single, why do we even support single-precision?&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;There are a number of reasons, but perhaps the most important are the following:&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.25in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .25in"&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;·&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;singles are half the size of doubles, reducing memory &amp;amp; bandwidth requirements.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.25in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .25in"&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;·&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;singles are the same size as DWORDs and thus can be moved in an atomic operation using 32bit integer registers (on occasion this can be important when doing things like InterlockedExchange on floating-point numbers).&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.25in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .25in"&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;·&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;some platforms support intrinsic, complicated operations in single-precision (e.g. SSE) but not in double precision&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.25in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .25in"&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;·&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;some hardware platforms do not natively support in-chip double precision computation; on such chips double precision must be emulated.&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.25in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .25in"&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;·&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Single precision computations are faster than double precision &lt;u&gt;on some platforms&lt;/u&gt;.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;However, it is NOT safe to assume that singles are always at least as fast as doubles.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;If double-precision is the native precision, the extra cost of narrowing results&amp;nbsp;to single-precision MAY be quite high… much higher, in fact, than the cost associated with the memory overhead of doubles (cache misses etc).&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.25in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .25in"&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;·&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;some 32-bit HW supports only integer operations—it’s faster to emulate single precision on these platforms than double precision&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.25in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .25in"&gt;&amp;nbsp;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;For many applications, it’s preferable to store input and final results in single precision, but to perform all the intermediate computations in the highest precision that is practical on the target architecture.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=329228" width="1" height="1"&gt;</content><author><name>ericflee</name><uri>http://blogs.msdn.com/members/ericflee.aspx</uri></author></entry><entry><title>Fused Multiply Add Question</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ericflee/archive/2004/12/17/323880.aspx" /><id>http://blogs.msdn.com/ericflee/archive/2004/12/17/323880.aspx</id><published>2004-12-18T01:45:00Z</published><updated>2004-12-18T01:45:00Z</updated><content type="html">&lt;p&gt;Sergey asks "Is there any chance that in MSVC++ 2005 Fused Multiply Add (FMA) function will be available as a part of runtime library on all supported platforms?"&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt; &lt;p&gt;To my knowledge FMAs won't be supported on all platforms since not all platforms have FMA instructions (some platforms don't even have floating point units!).&amp;nbsp; However, I think we're moving in that direction.&amp;nbsp; I'll try to find out for you with respect to the&amp;nbsp;x86 and x64&amp;nbsp;platforms.&amp;nbsp; In VC++, FMAs will&amp;nbsp;be used by default under the fp:precise when they're available on the architecture.&amp;nbsp; I believe that the fp:strict model precludes FMAs since it potentially violates strict FPU status semantics and exception semantics.&amp;nbsp; For instance, there are values for a*b+c where the fused operation returns a valid answer but the unfused operation overflows.&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/p&gt; &lt;p&gt;An interesting side point since I'm on the subject.&amp;nbsp; On ia64's FPU&amp;nbsp;and many other modern FPU architectures, separate multiply and add instructions aren't provided.&amp;nbsp; Two floating point registers are reserved to hold the values 0 and 1 respectively.&amp;nbsp; Simple addition is accomplished by using the 1 valued register as one of the multiply arguments; similarly simple multiplication is accomplished by using the 0 valued register as the addition argument.&amp;nbsp; &lt;/p&gt; &lt;p&gt; &lt;p&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=323880" width="1" height="1"&gt;</content><author><name>ericflee</name><uri>http://blogs.msdn.com/members/ericflee.aspx</uri></author></entry><entry><title>Method for getting /Op like consistency in MS C++ 14.0</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ericflee/archive/2004/07/28/200269.aspx" /><id>http://blogs.msdn.com/ericflee/archive/2004/07/28/200269.aspx</id><published>2004-07-28T23:53:00Z</published><updated>2004-07-28T23:53:00Z</updated><content type="html">&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: Verdana"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: Verdana"&gt;(From &lt;A href="http://msdn.microsoft.com/visualc/default.aspx?pull=/library/en-us/dv_vstechart/html/floapoint.asp"&gt;Microsoft Visual C++ Floating-Point Optimization&lt;/A&gt;) &lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;&lt;SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: Verdana"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in; LINE-HEIGHT: normal"&gt;&lt;SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: Verdana"&gt;Many C++ compilers offer a "consistency" floating-point model (through a /Op or /fltconsistency switch) that enables a developer to create programs compliant with strict floating-point semantics. When engaged, this model prevents the compiler from using most optimizations on floating-point computations while allowing those optimizations for non-floating-point code. The consistency model, however, has a dark-side. In order to return predictable results on different FPU architectures, nearly all implementations of /Op round intermediate expressions to the user specified precision; for example, consider the following expression:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE style="BACKGROUND: #d9d9d9; MARGIN: 6pt 0in 6pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; COLOR: black"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;float a, b, c, d, e; &lt;BR&gt;
&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;. . . &lt;BR&gt;
&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;a = b*c + d*e; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in; LINE-HEIGHT: normal"&gt;&lt;SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: Verdana"&gt;In order to produce consistent and repeatable results under /Op, this expression gets evaluated as if it were implemented as follows:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE style="BACKGROUND: #d9d9d9; MARGIN: 6pt 0in 6pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; COLOR: black"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;float x = b*c; &lt;BR&gt;
&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;float y = d*e; &lt;BR&gt;
&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;a = x+y; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in; LINE-HEIGHT: normal"&gt;&lt;SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: Verdana"&gt;The final result now suffers from single-precision rounding errors &lt;I&gt;at each step in evaluating the expression&lt;/I&gt;. Although this interpretation doesn't strictly break any C++ semantics rules, it's almost never the best way to evaluate floating-point expressions. It is generally more desirable to &lt;I&gt;compute the intermediate results in as high as precision as is practical&lt;/I&gt;. For instance, it would be better to compute the expression a=b*c+d*e in a higher precision as in,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"&gt;In short, the old /Op model trades away accuracy for consistency across platforms.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;For nearly all numerical programs, accuracy is preferable.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"&gt;This is precisely (no pun intended) the reason VC abandoned the consistency model altogether (and I fully expect other compiler makers to follow suite)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"&gt;There are however rare cases when consistency across platforms may be desired.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;In obviating the /Op model, Microsoft C++ 14.0 (in VS8.0) no longer provides a simple command line switch to enable cross-platform floating-point consistency.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;To get consistency across platforms, programmers will need to modify their source code.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;In the case from the whitepaper (above):&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE style="BACKGROUND: #d9d9d9; MARGIN: 6pt 0in 6pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; COLOR: black"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;float a, b, c, d, e; &lt;BR&gt;
&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;. . . &lt;BR&gt;
&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;a = b*c + d*e; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"&gt;the results of the expression b*c + d*e are dependant on the intermediate precision (i.e. the register precision) of the target platform.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;To enforce consistency across all platforms, users will need to introduce explicit narrowing operations at each point in the computation (setting _controlfp won&amp;#8217;t achieve the same results for reasons outlined in [1])&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE style="BACKGROUND: #d9d9d9; MARGIN: 6pt 0in 6pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; COLOR: black"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;float a, b, c, d, e; &lt;BR&gt;
&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;. . . &lt;BR&gt;
&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;a = &lt;B style="mso-bidi-font-weight: normal"&gt;float(&lt;/B&gt;b*c&lt;B style="mso-bidi-font-weight: normal"&gt;)&lt;/B&gt; + &lt;B style="mso-bidi-font-weight: normal"&gt;float(&lt;/B&gt;d*e&lt;B style="mso-bidi-font-weight: normal"&gt;)&lt;/B&gt;; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"&gt;Of course this is rather inconvenient to say the least.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;A more convenient method is to introduce a new &amp;#8220;wrapper&amp;#8221; class that will implicitly enforce consistency semantics.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Such a class will enable the code to be rewritten as &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE style="BACKGROUND: #d9d9d9; MARGIN: 6pt 0in 6pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;cfloat&lt;/B&gt; a, b, c, d, e; &lt;BR&gt;
&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;. . . &lt;BR&gt;
&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;a = b*c + d*e; &lt;SPAN style="COLOR: black"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"&gt;which is clearly a simpler and more elegant solution (I named it &amp;#8220;cfloat&amp;#8221; for &amp;#8220;consistent float&amp;#8221;).&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;By overloading the arithmetic operators for the wrapper class cfloat, we can make it behave as if it were the built in floating-point type.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"&gt;We begin by introducing a new type that wraps the floating point types (I&amp;#8217;ll only show single precision float here, however the same method would apply to a wrapper class for double or long double).&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;class cfloat&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;{&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;public:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;float value;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;cfloat() {}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;cfloat(const cfloat&amp;amp; v) : value(v.value) {}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;cfloat(float v) : value(v) {}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;. . .&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;I style="mso-bidi-font-style: normal"&gt;Similarly for types double and long doulble&lt;o:p&gt;&lt;/o:p&gt;&lt;/I&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"&gt;Naturally, we&amp;#8217;ll need the assignment operators:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;class cfloat&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;{&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;. . .&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;cfloat&amp;amp; operator = (const cfloat&amp;amp; v)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;value = v;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;return *this;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;cfloat&amp;amp; operator = (float v)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;value = v;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;return *this;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;I style="mso-bidi-font-style: normal"&gt;Similarly for each operator +=, -=, *=, and /=&lt;o:p&gt;&lt;/o:p&gt;&lt;/I&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"&gt;We&amp;#8217;ll also want to introduce explicit operators for narrowing values from double and long double precisions (note that long-double isn&amp;#8217;t strictly necessary)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;class cfloat&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;{&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;. . .&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;explicit cfloat(const cdouble&amp;amp; v) : value((float)v.value) {}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;explicit cfloat(double v) : value((float) v) {}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;I style="mso-bidi-font-style: normal"&gt;Similarly for each long double&lt;o:p&gt;&lt;/o:p&gt;&lt;/I&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"&gt;Then, introduce versions of each arithmetic operation &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;inline cfloat operator + (const cfloat&amp;amp; a, const cfloat&amp;amp; b)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;return a.value + b.value;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;inline cfloat operator + (float a, const cfloat&amp;amp; b)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;return a + b.value;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;inline cfloat operator + (const cfloat&amp;amp; a, float b)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;return a.value + b;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;I style="mso-bidi-font-style: normal"&gt;Similarly for -, *, and /&lt;o:p&gt;&lt;/o:p&gt;&lt;/I&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"&gt;Strictly speaking the 2&lt;SUP&gt;nd&lt;/SUP&gt; and 3&lt;SUP&gt;rd&lt;/SUP&gt; variations of the operators aren&amp;#8217;t necessary, but they do make debugging a bit easier.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"&gt;When the methods of the cfloat class are nicely inlined, the runtime performance of this class should be no worse than under the old /Op model.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 8pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 8pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=200269" width="1" height="1"&gt;</content><author><name>ericflee</name><uri>http://blogs.msdn.com/members/ericflee.aspx</uri></author></entry><entry><title>Method for retaining intermediate results in extended precision</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ericflee/archive/2004/07/21/190741.aspx" /><id>http://blogs.msdn.com/ericflee/archive/2004/07/21/190741.aspx</id><published>2004-07-22T00:30:00Z</published><updated>2004-07-22T00:30:00Z</updated><content type="html">&lt;FONT size=2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;I thought I&amp;#8217;d post a brief entry on how to retain intermediate results in extended precision.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;Consider the following direct summation algorithm:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;double sum(double[] a, int c)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&lt;EM&gt;1:&lt;/EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;double result = 0.0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&lt;EM&gt;2:&lt;/EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;for (int i=0; i&amp;lt;c; i++)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&lt;EM&gt;3:&lt;/EM&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;result = result + a[i];&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&lt;EM&gt;4:&lt;/EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;return result;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;Under fp:precise, the intermediate value of the addition operation (line 3) is held in register precision.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;However, the assignment operation explicitly forces the compiler to narrow the intermediate result to the target precision of the left-hand-side of the assignment&amp;#8212;in this case to &amp;#8220;double&amp;#8221;.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;To retain the extra precision of the in-register result it would be convenient to declare &lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;result&lt;/SPAN&gt; as:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;long double result = 0.0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;The summation would then be retained in long double precision and narrowed to double precision only when the function returns.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Unfortunately this doesn&amp;#8217;t work in VC++ because long doubles are stored at the same precision as doubles.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Although this is not a violation of C++ typing rules[&lt;/FONT&gt;&lt;A href="#REF"&gt;&lt;FONT face=Verdana&gt;1&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana&gt;], it is an inconvenience that many developers find rather annoying (myself included).&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Until recently, very few Visual C++ customers requested extended precision long doubles (though that&amp;#8217;s begun to change&amp;#8230; &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;I promise I&amp;#8217;ll write about this more in a later blog entry).&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;Even though extended precision long doubles aren&amp;#8217;t &lt;U&gt;yet&lt;/U&gt; supported in VC++, there are some &amp;#8220;tricks&amp;#8221; we can use to retain intermediate results in extended precision using VC++ in Visual Studio 8.0.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Let&amp;#8217;s look at how to do this for the summation algorithm above.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;For this algorithm what we really want is for the summation to be accumulated in a register&amp;#8212;that is, we want the compiler to &lt;I style="mso-bidi-font-style: normal"&gt;enregister&lt;/I&gt; the variable &lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;result&lt;/SPAN&gt;.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It would be especially nice if we could explicitly imply this semantic in our source code by adding the &lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;register&lt;/SPAN&gt; keyword to the declaration of &lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;result&lt;/SPAN&gt; (see my &lt;/FONT&gt;&lt;A href="http://weblogs.asp.net/ericflee/archive/2004/06/08/151481.aspx"&gt;&lt;FONT face=Verdana&gt;earlier post&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana&gt;).&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;However, there is a round-about way achieve this.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Under fp:fast semantics, the compiler is allowed to ignore the precision narrowing implication of the assignment operation on line 3; this relaxation of the narrowing rule permits the optimizer to enregister the variable &lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;result&lt;/SPAN&gt;.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;We can enable fp:fast semantics for a single function by wrapping it in float_control pragmas:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/B&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;#pragma float_control(except, off, push)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;#pragma float_control(precise, off)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;double sum(double[] a, int c)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;double result = 0.0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;for (int i=0; i&amp;lt;c; i++)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;result = result + a[i];&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;return result;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;#pragma float_control(precise, off, pop)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;With this change, the variable result&amp;nbsp;is allowed to be retained in a register at the full register precision.&amp;nbsp; &lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face=Verdana&gt;BEWARE: there are caveats to this solution, specific to each target architecture:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face=Verdana&gt;Targeting x86&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;When targeting x86 with VC++, the default FPU register precision is set to use 53bit significands (essentially a double).&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;To obtain a higher precision summation on x86, we need to set the register precision to use the full 64bit FPU significand provided by the x87 FPU.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;This is achieved by calling the _controlfp function, as follows, at some point before calling the function sum.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;_controlfp(_PC_64, _MCW_PC);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;This instructs the x87 FPU to use extended precision semantics in-register.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;This trick works with the summation algorithm and for many other tight-loop algorithms (e.g. Kahan&amp;#8217;s summation algorithm I showed in my FP whitepaper).&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Keep in mind that it will not work for every algorithm on x86 because any &amp;#8220;spilled&amp;#8221; registers will still be truncated to 53bit double precision (&lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/floapoint.asp"&gt;more info&lt;/A&gt;).&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It&amp;#8217;s also important to be aware of any unsafe side-effect optimizations that might take place in the body of the loop.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;I recommend this trick ONLY for x86 developers who are willing and able to inspect the assembly listing to check for the correct behavior.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;This trick subverts the intended semantics of&amp;nbsp;fp:precise and should be used with considerable care.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face=Verdana&gt;Targeting ia64&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;We have three advantages when using this trick on ia64.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Firstly, ia64 intermediate results are always in extended precision (64bits of precision in an 80bit result). &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;This means that the call to _controlfp required on x86 is not required on ia64. The second advantage is that the VC++ compiler for ia64 preserves the full 64bits of precision when spilling&amp;nbsp;FPU registers to memory.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;This means we don&amp;#8217;t have to worry about the issues involved with register spilling.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The third advantage is that the ia64 has many more floating-point registers than the x86 so there&amp;#8217;s more opportunity for the compiler to enregister variables under fp:fast semantics.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;There are however some distinct disadvantages.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Assembly code on ia64 can be &lt;U&gt;very&lt;/U&gt; difficult to read making it extremely hard to verify that the compiler produced the desired code.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The other disadvantage is that the compiler may attempt to perform unsafe optimizations that it wouldn&amp;#8217;t under fp:precise.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The &lt;I style="mso-bidi-font-style: normal"&gt;scalar reduction&lt;/I&gt; optimization in particular is an example of this:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;The scalar reduction optimization would effectively transform the sum function into&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;double sum(double[] a, int c)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;double s0, s1, s2, s3;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;s0 = s1 = s2 = s3 = 0.0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;int c4 = c &amp;amp; ~0x3;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;int i;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;for (i=0; i&amp;lt;c4; i+=4)&lt;BR&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;s0 = s0 + a[i];&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;s1 = s1 + a[i+1];&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;s2 = s2 + a[i+2];&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;s3 = s3 + a[i+3];&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;for (; i&amp;lt;c; i++)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;s0+=a[i];&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;return s0+s1+s2+s3;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;This optimization essentially reorders the operands.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Its important to note, however, that the extra-precision afforded by enabling fp:fast-semantics for this function may make up for the loss of strict accuracy caused by the reordering incurred with scalar optimization.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Moreover, many datasets and algorithms may not be sensitive to operand reordering so the speed advantage of the scalar optimized code may be compelling.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;As with x86, ia64 developers need to be careful when mixing in fp:fast semantics.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face=Verdana&gt;Targeting amd64&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;Unfortunately, this trick won&amp;#8217;t work when targeting amd64 because the compiler will only use SSE registers for floating-point operations (which have a maximum 53-bit significand).&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face=Verdana&gt;ALTERNATIVE TO THE &amp;#8220;TRICK&amp;#8220;:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;This kind of a trick can work pretty well in many cases.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;However, if you feel that it&amp;#8217;s just too much work to validate the generated assembly code, or if you think it&amp;#8217;s too risky, you can always use a compiler from another vendor for those particular functions needing extended precision long doubles; once compiled you can simply link the routines back into your VC++ application.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;I much prefer VC++&amp;#8217;s toolset over the competition and wouldn't care to abandon it wholesale over its lack of extended precision long doubles.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&lt;/FONT&gt;&lt;/o:p&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&lt;/FONT&gt;&lt;/o:p&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&lt;/FONT&gt;&lt;/o:p&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;A name=REF&gt;&lt;/A&gt;&lt;FONT face=Verdana&gt;[1] C/C++ standards only require that long doubles be stored in &lt;I style="mso-bidi-font-style: normal"&gt;at least&lt;/I&gt; the precision of double (ISO/IEC 9899:1999 &amp;#167;6.2.5.10)&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=190741" width="1" height="1"&gt;</content><author><name>ericflee</name><uri>http://blogs.msdn.com/members/ericflee.aspx</uri></author></entry><entry><title>Overloading the semantics of the register keyword (followup)</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ericflee/archive/2004/07/02/172210.aspx" /><id>http://blogs.msdn.com/ericflee/archive/2004/07/02/172210.aspx</id><published>2004-07-03T01:24:00Z</published><updated>2004-07-03T01:24:00Z</updated><content type="html">&lt;P dir=ltr style="MARGIN-RIGHT: 0px"&gt;John Albert asks&amp;nbsp;two questions: &lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P&gt;What would "register float" mean? &lt;BR&gt;How would this work under fp:fast? &lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The basic guideline is that "intermediate expressions will be computed in as high as precision as is practical". For instance, suppose for a particular architecture all double-precision computations have to be emulated (i.e. a chip that intrinsically supports only single precision computations). Under the guideline, its not at all practical to emulate double or extended precision when expressions contain only single precision operands. Thus for those architectures, &amp;#8220;register float&amp;#8221; would map to a single precision format corresponding to the intrinsic floating-point format. Higher precision expression would have to be emulated, so &amp;#8220;register double&amp;#8221; and &amp;#8220;register long double&amp;#8221; would map to the formats of the emulated expressions. &lt;BR&gt;&lt;BR&gt;Under fp:fast the type distinctiveness of &amp;#8220;register float&amp;#8221; would remain; however, the sizeof(register float) under fp:fast would be platform dependant. If the platform only supports a one precision level, then register float would map to that precision level. However, many platforms have multiple FPUs (e.g. x87 and SSE2 on Intel&amp;#8217;s chips). Because fp:fast allows for unsafe optimizations, the compiler can legally choose to perform some FP computations on one chip at higher-precision and some on the other chip at lower-precision. Under fp:fast I think it&amp;#8217;s reasonable to map &amp;#8220;register float&amp;#8221; to the least precise format used for computing single-precision operations. &lt;/P&gt;
&lt;P&gt;Its an interesting question; thanks John&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=172210" width="1" height="1"&gt;</content><author><name>ericflee</name><uri>http://blogs.msdn.com/members/ericflee.aspx</uri></author></entry><entry><title>No inline assembly on AMD64</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ericflee/archive/2004/07/02/172206.aspx" /><id>http://blogs.msdn.com/ericflee/archive/2004/07/02/172206.aspx</id><published>2004-07-03T01:18:00Z</published><updated>2004-07-03T01:18:00Z</updated><content type="html">&lt;P dir=ltr&gt;&lt;A id=Comments.ascx_CommentList__ctl1_NameLink target=_blank&gt;Igor Abramov&lt;/A&gt;&amp;nbsp;wrote:&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P&gt;&amp;#8220;Well, I was in desperate need for 80-bit long doubles. Now I coded this type as set&amp;nbsp;of asm inlines and application prototype shipped in such form. But the production version will be done for amd64, in 64-bit mode for performance reasons, and VS 2005 will not have inline assembler. This means rewriting some code again. &amp;#8220;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Because&amp;nbsp;VC++ in VS2005 doesn't allow for inline assembly when targeting amd64, you'll have to rewrite the inline assembly routines as pure assembly and then call them from C++.&amp;nbsp; However, inline assembly is still permitted&amp;nbsp;when targeting the x86 architecture.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;I'm no amd64 expert by any means&lt;/STRONG&gt;, but I'm told that using x87 80bit registers might not work because the current version of the OS for amd64&amp;nbsp;doesn't save the x87 FPU state when context switching; this is one of several reasons why the C++ compiler targets SSE instructions instead of x87 instructions.&amp;nbsp; I have heard, but don't quote me on this,&amp;nbsp;that future drops of the amd64 Windows OS will save the x87 FPU state.&lt;/P&gt;
&lt;P&gt;Perhaps someone reading this post could shed a brighter light on the issue.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=172206" width="1" height="1"&gt;</content><author><name>ericflee</name><uri>http://blogs.msdn.com/members/ericflee.aspx</uri></author></entry></feed>