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!news1.google.com!proxad.net!newsfeed1.ip.tiscali.net!tiscali!transit1.news.tiscali.nl!dreader2.news.tiscali.nl!not-for-mail Newsgroups: comp.lang.ada,comp.lang.c++,comp.realtime,comp.software-eng Subject: Re: [OT] Re: Teaching new tricks to an old dog (C++ -->Ada) References: <4229bad9$0$1019$afc38c87@news.optusnet.com.au> <1110032222.447846.167060@g14g2000cwa.googlegroups.com> <871xau9nlh.fsf@insalien.org> <3SjWd.103128$Vf.3969241@news000.worldonline.dk> <87r7iu85lf.fsf@insalien.org> <87is4598pm.fsf@insalien.org> <1110054476.533590@athnrd02> <1110059861.560004@athnrd02> From: Ludovic Brenta Date: Sun, 06 Mar 2005 00:29:35 +0100 Message-ID: <87wtsl7jts.fsf@insalien.org> User-Agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.3 (gnu/linux) Cancel-Lock: sha1:y+XOdjg4YNMjLejTJiLry5ivGkE= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: Tiscali bv NNTP-Posting-Date: 06 Mar 2005 00:29:14 CET NNTP-Posting-Host: 83.134.241.69 X-Trace: 1110065354 dreader2.news.tiscali.nl 44082 83.134.241.69:34571 X-Complaints-To: abuse@tiscali.nl Xref: g2news1.google.com comp.lang.ada:8695 comp.lang.c++:44245 comp.realtime:979 comp.software-eng:4510 Date: 2005-03-06T00:29:14+01:00 List-Id: Ioannis Vranos writes: > The restriction that you imply you desire, limits flexibility. Of course. That's what all these stories about shooting yourself in the foot mean. > Once again, I have nothing against learning Ada, however personally > I like the most powerful languages. The next thing I am going to > learn after C++ (because I haven't learned it all yet), is probably > some form of assembly language. Yes, assembly is the most powerful and flexible language. That's why all compilers emit assembler. > For example I like that I can do: [...] in Ada, you would use an overlaid array of characters, like this: with Ada.Strings.Unbounded; with Ada.Text_IO; procedure Unsafe_Proc is type Some_Class is record S : Ada.Strings.Unbounded.Unbounded_String; end record; Obj : aliased Some_Class := (S => Ada.Strings.Unbounded.To_Unbounded_String ("This is a text message")); Obj_As_String : String (1 .. Obj'Size / System.Storage_Unit); for Obj_As_String'Address use Obj'Address; begin for J in Obj_As_String'Range loop Ada.Text_IO.Put_Line (Integer'Image (Character'Pos (Obj_As_String (J))) & " " & Obj_As_String (J)); end loop; end Unsafe_Proc; Here, Ada makes it explicit that unsafe programming is taking place. First, Obj must be declared as "aliased", which means that two or more paths can access it. In our case, Obj and Obj_As_String are the two paths. This is another of Ada's nice safety-related features. Since aliasing must be made explicit, the reader of the program knows up front whether or not aliasing takes place. The reader of a C++ program has no such knowledge. Also, the writer of the program must think twice, and understand the consequences if they make an object aliased. Secondly, the representation clause for Obj_As_String ("for Obj_As_String'Address use ...") says exactly what is happening. I could make the code less verbose by using use clauses, similar to "using namespace std" which you seem fond of. In avionics, our coding standards forbid that because we want everything to be explicit. > I am sure that many ADA developers will say that this one is not > needed (the ability to access the individual bytes of objects is > needed in many cases, e.g. to create low level exact copies of > objects ) and it is unsafe (yes it is, low level stuff are unsafe > and it all depend on the programmer knowing what he does). I am an Ada (not ADA) developer, and I use overlaid structures as above in avionics software when necessary. However, Ada has better constructs for "low-level exact copies". Ada's representation clauses allow us to specify the bit pattern used for our low-level structures, all the way down to endianness of numbers or absolute addresses. > It is up to oneself to learn whatever languages fits his > purposes. For example, a "safe" language is not an interest for me. Then I am not interested entrusting my life to your software. > Someone who places much hopes on the language to protect him from > his mistakes, probably ADA is better than C++ on this. Hear, hear! > There is no language that provides satisfies all people desires, > just because some desires are in contrast between them. Agreed. Even in Ada, we sometimes use machine code insertions ("inline assembler") when we must. -- Ludovic Brenta.