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: 103376,703c4f68db81387d X-Google-Thread: 109fba,703c4f68db81387d X-Google-Thread: 115aec,703c4f68db81387d X-Google-Thread: f43e6,703c4f68db81387d X-Google-Attributes: gid103376,gid109fba,gid115aec,gidf43e6,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!t-online.de!tsicnews.teliasonera.com!news.otenet.gr!news.grnet.gr!newsfd02.forthnet.gr!not-for-mail From: Ioannis Vranos Newsgroups: comp.lang.ada,comp.lang.c++,comp.realtime,comp.software-eng Subject: Re: Teaching new tricks to an old dog (C++ -->Ada) Date: Wed, 23 Mar 2005 22:14:27 +0200 Organization: FORTHnet S.A., Atthidon 4, GR-17671 Kalithea, Greece, Tel: +30 2109559000, Fax: +30 2109559333, url: http://www.forthnet.gr Message-ID: <1111608867.922129@athnrd02> References: <395uqaF5rhu2mU1@individual.net> <1110329098.642196@athnrd02> <1110361741.551255@athnrd02> <422edaec$0$26554$9b4e6d93@newsread4.arcor-online.net> <1111464133.508323@athnrd02> <423fe9df$0$11476$9b4e6d93@newsread2.arcor-online.net> <1111521825.653841@athnrd02> <424094b0$0$11481$9b4e6d93@newsread2.arcor-online.net> <1111568404.687226@athnrd02> <1111572591.296439@athnrd02> <1111574207.72969@athnrd02> <42414f88$0$9217$9b4e6d93@newsread4.arcor-online.net> <1111576802.823362@athnrd02> <1111577078.934620@athnrd02> <1111586334.958702.249050@o13g2000cwo.googlegroups.com> NNTP-Posting-Host: athnrd02.forthnet.gr Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: athprx02.forthnet.gr 1111608868 28738 193.92.150.73 (23 Mar 2005 20:14:28 GMT) X-Complaints-To: abuse@forthnet.gr NNTP-Posting-Date: Wed, 23 Mar 2005 20:14:28 +0000 (UTC) User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en In-Reply-To: <1111586334.958702.249050@o13g2000cwo.googlegroups.com> Cache-Post-Path: newsfd02!unknown@ppp14-adsl-7.ath.forthnet.gr Xref: g2news1.google.com comp.lang.ada:9822 comp.lang.c++:46891 comp.realtime:1627 comp.software-eng:5229 Date: 2005-03-23T22:14:27+02:00 List-Id: fabio de francesco wrote: > Ciao, > > I think we don't have to care about the presence of a high-level > construct like whatever container. When C++ hadn't yet standardised > containers, everyone could actually build these higher-level structures > by himself. The only problem is standardisation. If you have languages > that are sufficienly low-level like C++ and Ada you can manufacture > every type of algorithm and containers you need. > > You build higher-level components by using lower-level built-in > language features. Every compile-time or run-type check that you can > have for built-in types you "inherit" for user created structures. This > is said to answer your past question about Ada having or not same > checks for built-in types and user defined types. OK. > I suppose std::vector is a simple array which must be copied to a > larger one in order to insert a new element while it is full. You know > it can be done in Ada too. It is not that expensive. An implementer reserves some more space so as to avoid frequent reallocations, and vector provides reserve() method to allocate unitialised space for objects since the beginning by yourself, if you are going to insert many objects later, so as to avoid reallocation. For example: // Contains 10 ints initialised to 0. vector vec(10); // Reserves unitialised memory space for 1000 ints in total vec.reserve(1000); > What's more in Ada is that you can, in a standardised way, directly > create low-level representation of user defined types with a lot of > attributes that C++ doesn't provide. Ada programmers prefer to build > their own types rather than using built-in Integer, Float, Long_Float > (int, float, double) and so on in order to gain a much finer control. > > In Ada you can decide representation attributes like range, digit, > delta, mod, address, alignment, size, byte-order (little or big endian) > in record component, and many other things like these. As an example > you can write: > > type Counter is new Integer; > for Counter'Size use 48; > for Counter'Alignment use 16; > > What's more, you get a compiler error if your machine can't use some > sort of representation you need in order to free you from knowing how > much space a type can provide. > > You said that real C++ code hardly need to specify ranges, because you > should be careful not to assign a value that can't be held by a > variable of some specific type. Imagine you have know a variable is to > hold numbers not larger than 99_999 and you choose to store them in an > "int" knowing that you have enough space. When later you port your > program to a machine where "int" is 16 bits you don't have any warning > from a C++ compiler and program run for years until for some reason > that variable is assigned with say 86_000. I think you know what > happens.. The standard guarantees the minimum ranges, for int can hold at least 16-bit values and long at least 32-bit values. > If you had that type declared as "type Var_T is range 0 .. 99_999;", at > the very moment you port your program to this new machine the compiler > would choose the correct size to hold values of that type so program is > no more restricted to this 16 bits C++ "int" and consequently won't > raise this bug. > > Do you still think you don't need ranges? Ranges are a nice thing to have, however if you are provided with minimum range guarantees, this also does the job. I would prefer compiler error messages for out of range assignments though. And I wonder what backwards compatibility (apart from -1 assignment to unsigned integral types) this would break. -- Ioannis Vranos http://www23.brinkster.com/noicys