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.1 required=5.0 tests=BAYES_00,FREEMAIL_FROM, PP_MIME_FAKE_ASCII_TEXT autolearn=no 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,UTF8 Path: g2news1.google.com!news3.google.com!news.glorb.com!wn13feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!53ab2750!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) From: Jim Rogers 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> Followup-To: comp.lang.ada,comp.lang.c++ User-Agent: Xnews/5.04.25 Message-ID: Date: Sun, 06 Mar 2005 00:41:51 GMT NNTP-Posting-Host: 12.73.180.69 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1110069711 12.73.180.69 (Sun, 06 Mar 2005 00:41:51 GMT) NNTP-Posting-Date: Sun, 06 Mar 2005 00:41:51 GMT Organization: AT&T Worldnet Xref: g2news1.google.com comp.lang.ada:8698 comp.lang.c++:44251 comp.realtime:982 comp.software-eng:4513 Date: 2005-03-06T00:41:51+00:00 List-Id: Ioannis Vranos wrote in news:1110059861.560004@athnrd02: > > 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. > > > For example I like that I can do: > > #include > #include > #include > #include > > class SomeClass > { > std::string s; > > public: > SomeClass() > { > s="This is a text message"; > } > }; > > > int main() > { > using namespace std; > > SomeClass obj; > > unsigned char *p= reinterpret_cast(&obj); > > // Displays the individual bytes that obj > // consists of as unsigned chars. > for(unsigned i=0; i cout<<"character: "< > cout<<"\n"; > > > p= reinterpret_cast(&obj); > // Displays the decimal values of the > // individual bytes that obj consists of. > for(unsigned i=0; i cout<(p[i])<<" "; > > cout<<"\n\n"; > > > // Displays the bits of each byte that consist > // this SomeClass object > p= reinterpret_cast(&obj); > for(unsigned i=0; i { > // A byte is not necessarily 8 bits > // numeric_limits::digits retrieves the > number // of byte's bits, which *is* 8 usually. > bitset::digits> bits(p[i]); > > for(unsigned j=0; j cout< > cout<<"\n"; > } > } > > > C:\c>temp > character: ⁿ > character: = > character: > > character: > > 252 61 62 0 > > 00111111 > 10111100 > 01111100 > 00000000 > > C:\c> > All this can be done in Ada. How good is C++ at exactly representing bit fields? Can C++ do this portably: type Byte is mod 2**8; type Sign_Flag is mod 2; type Mouse_Status_Type is record Left_Button_Pressed : Boolean; Right_Button_Pressed : Boolean; X_Movement_Sign : Sign_Flag; Y_Movement_Sign : Sign_Flag; X_Movement_Overflow : Boolean; Y_Movement_Overflow : Boolean; X_Movement_Magnitude : Byte; Y_Movement_Magnitude : Byte; end record; for Mouse_Status_Type use record Left_Button_Pressed at 0 range 0..0; Right_button_Pressed at 0 range 1..1; X_Movement_Sign at 0 range 4..4; Y_Movement_Sign at 0 range 5..5; X_Movement_Overflow at 0 range 6..6; Y_Movement_Overflow at 0 range 7..7; X_Movement_Magnitude at 1 range 0..7; Y_Movement_Magnitude at 2 range 0..7; end record; The type Mouse_Status_Type defines a data structure that occupies three bytes. The first 6 fields of the record occupy a single bit each, with bits 2 and 3 unused. Furthermore, access to the individual fields of this record are very direct, not requiring arcane bit masks. foo : Mouse_Status_Type; if foo.Left_Button_Pressed then do_something; end if; > > 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). > On the contrary, Ada is frequently used for low level bit manipulation. Ada was designed to be used in safety-critical hard real-time embedded systems. > > It is up to oneself to learn whatever languages fits his purposes. For > example, a "safe" language is not an interest for me. We are all free to have our own interests. I do ask that you look at the capabilities of a language before you decide they are not in your interest. Ada does not prevent you from doing unsafe things. It simply does not provide an unsafe behavior as its default. > > Someone who places much hopes on the language to protect him from his > mistakes, probably ADA is better than C++ on this. Programming is a human activity. All humans make mistakes. Some of those mistakes are damned silly. Ada is designed to acknowledge that programmers are human. Mistakes will be made. Ada attempts to identify those mistakes as early in the development process as possible. We all know that it is cheaper to fix mistakes early. > > > There is no language that provides satisfies all people desires, just > because some desires are in contrast between them. And there is no perfect language. Ada is not meant to satisfy the desires of all programmers. It is meant to support programming as a human activity with the goal of producing high quality programs very efficiently. Jim Rogers