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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c9d5fc258548b22a X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!transit3.readnews.com!transit4.readnews.com!news-out.readnews.com!postnews7.readnews.com!not-for-mail Date: Tue, 08 Feb 2011 16:25:30 -0500 From: Hyman Rosen User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: How do I write directly to a memory address? References: <67063a5b-f588-45ea-bf22-ca4ba0196ee6@l11g2000yqb.googlegroups.com> <19fh1chm74f9.11cws0j5bckze.dlg@40tude.net> <4d4ff70e$0$6886$9b4e6d93@newsspool2.arcor-online.net> <737a6396-72bd-4a1e-8895-7d50f287960e@d28g2000yqc.googlegroups.com> <4d5008a5$0$6879$9b4e6d93@newsspool2.arcor-online.net> <4d5031fe$0$6765$9b4e6d93@newsspool3.arcor-online.net> <1f229967-d3cf-42b6-8087-c97ee08652f3@i40g2000yqh.googlegroups.com> <4d51169e$0$7657$9b4e6d93@newsspool1.arcor-online.net> <1bnp0pw1c8r5b$.guxc48qweiwe.dlg@40tude.net> <4d51a1c0$0$19486$882e7ee2@usenet-news.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <4d51b568$0$19486$882e7ee2@usenet-news.net> NNTP-Posting-Host: 9e45d624.usenet-news.net X-Trace: DXC=C;F<5X5WZN30oY=4m@aX^:KNd2lZeh5cD4 X-Complaints-To: abuse@usenet-news.net Xref: g2news2.google.com comp.lang.ada:18015 Date: 2011-02-08T16:25:30-05:00 List-Id: On 2/8/2011 4:09 PM, Shark8 wrote: > On Feb 8, 1:01 pm, Hyman Rosen wrote: >> How is it the fault of C that we now program on these platforms? > > Because managers have had reinforced the erroneous idea that: > "C is the *only* valid systems-level language." for one. Huh? Web, smart-phone, and other complex interfaces exist because of C? That makes no sense. >> How do you test the third bit of a byte in Ada? > > One Way, assuming a 1..8 numbering for an 8-bit byte: > SubType Bits is Positive Range 1..Byte'Size; > Type Bit_Mask is Array ( Bits'Range ) of Boolean; > For Bit_Mask'Size use Byte'Size; > > Function Test_Bit( Value : In Byte; Bit : In Bits ) Return Boolean is > Mask : Bit_Mask; > For Mask'Address use Value'Address; > Pragma Import( Ada, Mask ); > begin > Return Mask(Bit); > end Test_Bit; I think that's why I'll stick with (byte & (1 << (3 - 1))). Or rather, I would most likely write a macro, #define TEST_BIT(n, b) ((n) & (1 << ((b) - 1))) Then the Ada people who see errors in every line of C code would come after me complaining about how terrible my code is, and what if the macro is invoked with zero or negative or too high bit number. >> *Why* do you test the third bit of a byte in any language? > > Why does a hardware device set the third bit of some information? > To communicate. Except for DK, who granted was actually interviewing people to work with such hardware devices, programming doesn't really involve such bit twiddling any more. It doesn't even involve being able to design data structures much any more either. These days, someone working in Java or C++ will just pick an appropriate container class from the library and use it, and it will be good enough.