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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,b92b95c9b5585075 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder.news-service.com!feeder.news-service.com!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Brian Drummond Newsgroups: comp.lang.c++,comp.lang.ada Subject: Re: Why use C++? Date: Sat, 13 Aug 2011 11:54:39 +0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: <1e292299-2cbe-4443-86f3-b19b8af50fff@c29g2000yqd.googlegroups.com> <1fd0cc9b-859d-428e-b68a-11e34de84225@gz10g2000vbb.googlegroups.com> <9ag33sFmuaU1@mid.individual.net> <1d8wyhvpcmpkd.ggiui9vebmtl.dlg@40tude.net> <150vz10ihvb5a.1lysmewa1muz4$.dlg@40tude.net> <1q4c610mmuxn7$.1k6s78wa0r8fj.dlg@40tude.net> <1vn800hbyx8k4$.1lsveclj56197$.dlg@40tude.net> <1gu6ni1yb54k3$.4nbvfqqndl8m$.dlg@40tude.net> <9amuf2FdetU3@mid.individual.net> <9an4doFdeuU2@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Sat, 13 Aug 2011 11:54:39 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="BfPUyNRlm90yTQpY2xmuXQ"; logging-data="28592"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+rMf3fOp5fNFhwEokYL7pUmt2JY8DLEQA=" User-Agent: Pan/0.134 (Wait for Me; GIT cb32159 master) Cancel-Lock: sha1:cmvE74kBbbh67PavmgtSNZ+ExfE= Xref: g2news1.google.com comp.lang.c++:82926 comp.lang.ada:20602 Date: 2011-08-13T11:54:39+00:00 List-Id: On Sat, 13 Aug 2011 23:10:48 +1200, Ian Collins wrote: > On 08/13/11 09:52 PM, Dmitry A. Kazakov wrote: >> On Sat, 13 Aug 2011 21:29:05 +1200, Ian Collins wrote: >> >>> It's pretty rare for the application domain to be concerned about the >>> semantics of an integer beyond those specified by the language. >> >> If buffer overflows and code quality is not a concern, then yes. > > Most variables have limited scope and a well defined range. So if I use > an int in a for loop over a small set of data, I'm not writing poor > quality code. Yes you are (in this hypothetical example), if you care about either reliability or efficiency. By specifying "int" you are prohibiting the compiler from both: (a) using a smaller and possibly faster type that is adequate to cover the range of data. and (b) using a larger type if "int" does not actually cover the range. Specify user-defined types "range 1 .. 100" or "range 32760 ..32769" or "range lower .. upper" and let the compiler choose the optimal base type for the current target. (Imagine using "int" here on a 16-bit platform) Incidentally, the values of "lower" and "upper" need not be determined until runtime. The compiler can infer the best base type from whatever constraints it finds on "lower" and "upper". So why get in its way? - Brian