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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,54c513170bafd693 X-Google-Attributes: gid103376,public From: "Robert I. Eachus" Subject: Re: Desirability of C++ Date: 2000/05/04 Message-ID: <391198AB.BB1D1DA1@earthlink.net> X-Deja-AN: 619180997 Content-Transfer-Encoding: 7bit References: <390DEC7F.9429C82C@online.no> <390E2A20.B647D0D6@maths.unine.ch> <8em8mb$evd$1@wanadoo.fr> <390EEF24.BD36AA24@maths.unine.ch> <390FBAD0.7CECA91A@earthlink.net> X-Accept-Language: en,pdf Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 957454474 63.24.56.194 (Thu, 04 May 2000 08:34:34 PDT) Organization: The MITRE Corporation MIME-Version: 1.0 NNTP-Posting-Date: Thu, 04 May 2000 08:34:34 PDT Newsgroups: comp.lang.ada Date: 2000-05-04T00:00:00+00:00 List-Id: Robert A Duff wrote: > I don't see why. It makes perfect sense to assign a max-5 string into a > max-10 string, and it can't fail at run time. I could understand > wanting to reject assignments from max-10 to max-5, because otherwise > that might fail at run time. Because there is a conversion there, and it is unusual enough that I don't want it to be an implicit conversion. I may know that: Full_Name := First_Name & ' ' & Middle_Name & ' ' & Last_Name; is an assignment that will never fail, but I prefer to write explicitly: Full_Name := To_Bounded_String(First_Name & ' ' & Middle_Name & ' ' & Last_Name); what is so difficult about that? Of course, if you are one of those poor souls who has to live with restrictions on use clauses, don't blame me. I said: > > If you really get upset about explicit conversions, > > then instantiate Bounded_String once, with the maximum of all the > > maximum sizes. > > Then you waste memory on the strings that could have been small. > If you think different max sizes are useful at all, then surely > you will want to make different choices in different cases. (Bob's words above seem to imply that I am in favor of something that I am not, and my words imply that he is in favor of something that he is not. I don't think either of us is confused, but that this is a case where informal English is inherently confusing--all uses of "you" above are indefinite placeholders, not the second person pronoun.) I don't "waste" memory on such things, although I don't really worry about such a detail as a waste in any case. There are cases in databases where fields will be stored uncompressed, but in general inserting "blank space" in data records will not increase the size of a file due to compression. I personally prefer to use different instances of Bounded_String for different types of data, even when the max sizes are the same. I like the diagnostics I get. > Surely you don't mean "cannot". If you write 16 instantiations of > Ada.Strings.Bounded in your program, you will get 16 copies of the code, > on most compilers. Perhaps you mean that a clever compiler could share > the code? If the compiler you use does not pay attention to the possibility of multiple instances of Ada.Strings.Bounded in a program, then yes you could get code bloat when you compile thirty different packages containing instances of Ada.Strings.Bounded, whether or not they are the same size. But if this is broken in your implementation, then this is a minor issue compared to multiple instances of the generics in Text_IO. However, in reality, no implementation of Ada.Strings.Bounded should generate ANY code. There are interfaces which should map to calls to non-generic library routines, and there are interfaces which are to routines that should result in little or no code. So, as far as I am concerned, every subroutine in Ada.Strings.Bounded should have a pragma Inline in the private part. > One. But it's not terribly useful, being inside a recursive function > where I can't get at it. Okay, so you are saying that compiler writers will correctly do generic instantiation at run-time when they must do it at run-time, but otherwise they will bloat the code? If you are using a compiler that is that brain dead, just put all your instantiations inside the main program, with parameters that cannot be evaluated until run-time. But I find this very hard to believe. An instantiation of Ada.Strings.Bounded must create an object, which may be required to be on the stack. That object may contain a code pointer, but the code can't go on the stack in most architectures. If that is the only possible way to implement some instantiations, why would a compiler choose to go to a lot of extra effort to handle some other cases wrong? (As I said, I can imagine a compiler that won't recogize the existance of several instantiations of Ada.Stings.Fixed in different compilations and will create different code modules, but not recognizing multiple instances in the same compilation is just dumb. What does gnat do here? (Seems to me that gnat should trivially detect identical generic instances which are library units, but may not do code sharing for nested instances in different compilations.)