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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no 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 A Duff Subject: Re: Desirability of C++ Date: 2000/05/03 Message-ID: #1/1 X-Deja-AN: 618709776 Sender: bobduff@world.std.com (Robert A Duff) References: <390DEC7F.9429C82C@online.no> <390E2A20.B647D0D6@maths.unine.ch> <8em8mb$evd$1@wanadoo.fr> <390EEF24.BD36AA24@maths.unine.ch> <390FBAD0.7CECA91A@earthlink.net> Organization: The World Public Access UNIX, Brookline, MA Newsgroups: comp.lang.ada Date: 2000-05-03T00:00:00+00:00 List-Id: "Robert I. Eachus" writes: > Robert A Duff wrote: > > > ...Apparently, Turbo Pascal actually makes assignment work, which is > > obviously preferable to either of the above Ada alternatives. > > I guess I don't see this. In Ada, you have several choices: String, > Bounded_String, and Unbounded_String. Each is appropriate in different > places, and, yes it can be painful if you are forced--by ignorance or > management--to use the wrong abstraction for the job at hand. I was only talking about cases where bounded strings *are* appropriate. In that case, a comparison can be made between the Ada and Turbo Pascal support. (Several dialects of Pascal had similar features, actually.) > But when an instance of Bounded_String is the appropriate choice, it > has always been my experience that you WANT the compiler to reject > assignments between objects with different maximum sizes. 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. >... That is > almost always either a bug or a situation that code to handle the > potential mismatch. 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. > The other thing to note is that having multiple instances of > Bounded_Strings in your program cannot result in code bloat. 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? >...Hint: > Write a program that reads a number from Current_Input, then calls a > subroutine that recursively calls itself and on each call, instantiates > Ada.Strings.Bounded for a different maximum length: > > function Recur(N: Natural) return String is > package BS is new Ada.Strings.Bounded(N); > begin > if N > 0 > then > return Recur(N-1) & 'X'; > else return ""; > end if; > return end Recur; > -- put in some code that exercises the instance if you want... > > How many copies of the code for Ada.Strings.Bounded are there in your > executable? Can you call Recur with a larger value of N? One. But it's not terribly useful, being inside a recursive function where I can't get at it. - Bob