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-Attributes: gid103376,gid109fba,public X-Google-Language: ENGLISH,UTF8 Path: g2news1.google.com!news3.google.com!news.glorb.com!newscon02.news.prodigy.com!newscon06.news.prodigy.com!prodigy.net!newsfeed-00.mathworks.com!bigboote.WPI.EDU!news.tufts.edu!uunet!ash.uu.net!newsfd02.forthnet.gr!not-for-mail From: Ioannis Vranos Newsgroups: comp.lang.ada,comp.lang.c++ Subject: Re: [OT] Re: Teaching new tricks to an old dog (C++ -->Ada) Date: Sun, 06 Mar 2005 03:23:43 +0200 Organization: FORTHnet S.A., Atthidon 4, GR-17671 Kalithea, Greece, Tel: +30 2109559000, Fax: +30 2109559333, url: http://www.forthnet.gr Message-ID: <1110072229.85604@athnrd02> 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> NNTP-Posting-Host: athnrd02.forthnet.gr Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Trace: athprx02.forthnet.gr 1110072229 4099 193.92.150.73 (6 Mar 2005 01:23:49 GMT) X-Complaints-To: abuse@forthnet.gr NNTP-Posting-Date: Sun, 6 Mar 2005 01:23:49 +0000 (UTC) User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en In-Reply-To: Cache-Post-Path: newsfd02!unknown@ppp36-adsl-149.ath.forthnet.gr Xref: g2news1.google.com comp.lang.ada:8706 comp.lang.c++:44262 Date: 2005-03-06T03:23:43+02:00 List-Id: Jim Rogers wrote: >>C:\c>temp >>character: ⁿ >>character: = >>character: > >>character: >> >>252 61 62 0 >> >>00111111 >>10111100 >>01111100 >>00000000 >> >>C:\c> >> > > All this can be done in Ada. It would be great if we saw the code and its output. > How good is C++ at exactly representing bit fields? > > Can C++ do this portably: Some explanations with remarks in the code along with the output, would make things easier to understand. > 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. I guess the C++ equivalent is: struct SomeStruct { unsigned Left_Button_Pressed: 1; unsigned Right_button_Pressed: 1; unsigned X_Movement_Sign: 1; unsigned Y_Movement_Sign: 1; unsigned X_Movement_Overflow: 1; unsigned Y_Movement_Overflow: 1; unsigned X_Movement_Magnitude: 8; unsigned Y_Movement_Magnitude: 8; }; It is interesting to see that ADA supports this. > 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; The above in a simple C++ program: #include int main() { struct SomeStruct { unsigned Left_Button_Pressed: 1; unsigned Right_button_Pressed: 1; unsigned X_Movement_Sign: 1; unsigned Y_Movement_Sign: 1; unsigned X_Movement_Overflow: 1; unsigned Y_Movement_Overflow: 1; unsigned X_Movement_Magnitude: 8; unsigned Y_Movement_Magnitude: 8; }; SomeStruct obj= {1, 0, true, false, 1, 16, 64}; if(obj.Left_Button_Pressed) std::cout<<"It is pressed!\n"; } C:\c>temp It is pressed! C:\c> > 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 interesting to hear that. > 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. Perhaps I will check it sometime in the future. > > >>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. Yes, however I have the feeling that it does so by imposing several restrictions that apart from protecting from possible misuses, also prevent from flexible uses. Again, this is just a feeling, I have not studied the language. > 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. OK. -- Ioannis Vranos http://www23.brinkster.com/noicys