From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3885b7fd66a1db28 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-01-10 01:26:43 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!HSNX.atgi.net!falcon.america.net!uunet!dca.uu.net!ash.uu.net!spool0902.news.uu.net!not-for-mail Date: Fri, 10 Jan 2003 04:26:21 -0500 From: Hyman Rosen User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3a) Gecko/20021212 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Why is Ada NOT a good choice for a beginner to programming? References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Organization: KBC Financial Products Message-ID: <1042190781.488452@master.nyc.kbcfp.com> Cache-Post-Path: master.nyc.kbcfp.com!unknown@nightcrawler.nyc.kbcfp.com X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) NNTP-Posting-Host: 204.253.250.10 X-Trace: 1042190782 12164 204.253.250.10 Xref: archiver1.google.com comp.lang.ada:32870 Date: 2003-01-10T04:26:21-05:00 List-Id: Grein, Christoph wrote: > For me, the code posted looked like Kazakov's solution with run-time handling of > dimension exponents. Your reply now seems to say that C++ does the checking and > exponent addition during compile time. Is that true? Yes. All those exponents are part of the type, not the object. When you multiply or divide two units, the compiler can find only one specialization of the operator* or operator/ template which accepts the correct parameters, and is therefore forced to synthesize the correct return type. C++ instantiates the correct operator for you; in Ada, you would have to request a generic instantiation before you could use it. Meanwhile, addition and subtraction are defined only for two unit operands of the same type (that is, all exponents equal), so any attempt to add disparate units will not compile. Unit objects don't need to carry around type information at runtime, so they are only as large as the type used to hold their numeric value. Any half-decent C++ compiler will also inline all the arithmetic, so the compiled code should look just like arithmetic on the underlying type, with no runtime overhead at all for the units checking. This technique works only when all units are statically present in the code, naturally. My code is the bare skeletal outline of the approach, of course.