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,ASCII-7-bit Path: g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!news-feed01.roc.ny.frontiernet.net!nntp.frontiernet.net!uunet!dca.uu.net!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 06:09:00 +0200 Organization: FORTHnet S.A., Atthidon 4, GR-17671 Kalithea, Greece, Tel: +30 2109559000, Fax: +30 2109559333, url: http://www.forthnet.gr Message-ID: <1110082147.830198@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> <1110072229.85604@athnrd02> NNTP-Posting-Host: athnrd02.forthnet.gr Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: athprx02.forthnet.gr 1110082147 15536 193.92.150.73 (6 Mar 2005 04:09:07 GMT) X-Complaints-To: abuse@forthnet.gr NNTP-Posting-Date: Sun, 6 Mar 2005 04:09:07 +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:8720 comp.lang.c++:44281 Date: 2005-03-06T06:09:00+02:00 List-Id: Jim Rogers wrote: > The program declares a string S initialized to "This is a text message". > It then declares an array type named Bits_Array. That array type is an > array of Boolean, with the number of elements equal to the number of > bits in used by S. The variable L is set to equal the value returned > by the Size attribute of the String S. Ada reports size as the number > of bits, not the number of bytes. > > A packed array of boolean allocates one storage element to each bit. > Therefore, the statement > pragma Pack(Bits_Array); > causes all instances of Bits_Array to be a packed array. > The variable Bits is declared to be of the type Bits_Array. > The next statement forces Bits to overlay S. Both variables > are the same size and start at the same address. Does this mean that Boolean always occupies 1 bit and has no padding bits? > The body of the procedure simply iterates through all the bits in > the Bits variable and prints the numeric value of each bit. > A new line is output whenever the loop control variable mod > System.Storage_Unit evaluates to 0. System.Storage_Unit is > provided by Ada so that the program will properly represent > each storage unit (sometimes called a byte) no matter what the > size of that unit is. > > As you can clearly see, Ada can represent the bits of a > variable with very little difficulty. > > Ada does not store a null at the end of a string. This is > why there is no indication of a null value for the last byte. While this is an interesting thing, I have the feeling that this approach does not print all bits, including padding bits, of a *user-defined type*. In C++ you can read (and thus copy, print or anything) every byte of any type. In the example you provided, I have the feeling that you allocated a character array (the string) and then treated is a boolean array (somewhat a hacking attempt to imitate the behaviour). However what happens in the case of a user defined type (I suppose Ada supports OO programming) or a record. Can you print the byte implementation of such an object? Also for a built in type, say a floating point, can you print its implementation bytes too (including padding bits)? Consider this: #include #include #include int main() { using namespace std; double obj= 0.45435; unsigned char *p= reinterpret_cast(&obj); p= reinterpret_cast(&obj); // Displays the decimal values of the // individual bytes that obj consists of. for(unsigned i=0; i(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::digits retrieves the number // of byte's bits, which *is* 8 usually. bitset::digits> bits(p[i]); for(unsigned j=0; jtemp 163 1 188 5 18 20 221 63 11000101 10000000 00111101 10100000 01001000 00101000 10111011 11111100 C:\c> -- Ioannis Vranos http://www23.brinkster.com/noicys