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-Thread: 109fba,cd8ed9115942852f X-Google-NewGroupId: yes X-Google-Thread: 103376,b92b95c9b5585075 X-Google-NewGroupId: yes X-Google-Attributes: gid4f1905883f,gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.lang.c++,comp.lang.ada Subject: Re: Why use C++? Date: Sat, 13 Aug 2011 23:10:48 +1200 Message-ID: <9an4doFdeuU2@mid.individual.net> 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> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net hsGNwT40HS4Rkql4kdLGOwrSNHaaAQ48gX6Ag9djEaPiyZoCR9 Cancel-Lock: sha1:j0T/Ai9rC1qL0kM3MmZgoAZKJf8= User-Agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20101021 Lightning/1.0b2 Thunderbird/3.1.4 In-Reply-To: Xref: g2news1.google.com comp.lang.c++:82923 comp.lang.ada:20600 Date: 2011-08-13T23:10:48+12:00 List-Id: 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. >>>>> In each such case I will have to use a type different from the machine >>>>> type. This is just another argument why types need to be precisely >>>>> specified. I addressed this issue above. >>>> >>>> But they are precisely specified on any given platform. >>> >>> 1. They are not. In order to see the specification of int, you have to read >>> the compiler documentation. My point was that the program code does not >>> specify the properties of int. The answer that it is defined somewhere >>> somehow is not an argument at all, anything works in this or that way. >> >> If you want to get the best performance out of a given platform (which >> many C and C++ programs do), you have to program to the characteristics >> of the platform. > > First of all, performance is not a functional requirement. It very often is the first one for most of the embedded systems I write! > If functional > requirements are not met, non-functional ones are irrelevant. The functional requirements are irrelevant if they can not be met in the required time. > Thus the > question stands: what does int implement? Where in the program code is any > specification of the *functional* requirements which the implementation > chosen to be int is supposed to fulfill [in the best etc possible way, > which in its turn requires validation]? How do I know if int is OK, not > unsigned, not long, not short and so on? In general, you can't. Where it matters, you have to measure. > Secondly, how do you know that int gives you the best performance across > all possible implementations fulfilling the functional requirements? By > choosing int you prohibit the compiler to select any other machine type, > which also does the things you want. The point is, specify what you want > and let the compiler to implement it in a best possible way. Choosing an > implementation is an optimization issue, you can aim at memory use, at > time, at best lock-free sharing and so on. Fixing a machine type makes your > program potentially less efficient. More precisely you specify the > semantics of required type, more knowledge the compiler has to generate > efficient code. I do see your point and for C or C++ the best we can do knowing a variable is signed or unsigned of a given range is to use one of the C fast_xx types. Far from ideal I know. Yes I agree being able to specify a type without reference to an underlying fundamental type is a powerful feature C and C++ lack. -- Ian Collins