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,21960280f1d61e84 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wn13feed!worldnet.att.net!bgtnsc05-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail From: Dave Thompson Newsgroups: comp.lang.ada Subject: Re: How come Ada isn't more popular? Message-ID: <5rigs215675tlmql11ens5idv0188eqrut@4ax.com> References: <1169531612.200010.153120@38g2000cwa.googlegroups.com> <1169588206.234714.312650@k78g2000cwa.googlegroups.com> <1169624573.534128.172610@s48g2000cws.googlegroups.com> <87sle0sv9o.fsf@ludovic-brenta.org> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Tue, 06 Feb 2007 09:54:44 GMT NNTP-Posting-Host: 12.76.14.20 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1170755684 12.76.14.20 (Tue, 06 Feb 2007 09:54:44 GMT) NNTP-Posting-Date: Tue, 06 Feb 2007 09:54:44 GMT Organization: AT&T Worldnet Xref: g2news2.google.com comp.lang.ada:9017 Date: 2007-02-06T09:54:44+00:00 List-Id: On Wed, 24 Jan 2007 09:07:15 +0100, Ludovic Brenta wrote: > On the contrary, I think that Ada is the most expressive language > around. Consider: > > procedure Set_Bit_In_Register (At_Address : in System.Address) is > type Register is array (1 .. 32) of Boolean; > pragma Pack (Register); > for Register'Bit_Order use System.High_Order_First; > pragma Volatile (Register); > > R : Register; > for R'Address use At_Address; > begin > Register (4) := True; > end; > Even if this combination is/was actually supported (and MSB means highest-subscript, which I don't find all that obvious) ... > versus > > void set_bit_in_register (volatile unsigned long * at_address) > { > *at_address |= 2 << 3; > } > You presumably meant 1 << 3 (zero-origin numbering) to match subscript 4 (one-origin). But to be safe in the (more) general case you need 1UL << B, since promotion in C is strictly bottom-up (no expected-type context) and the literal defaults to type 'int' which _might_ be only 16 bits while 'long' must be at least 32 bits. And you might even want an assert( B < 32 /* or other M */ ); (or environment/project-specific equivalent). > The Ada version makes many more things explicit, that are assumed and > implicit in C; for example, the size of the register, the fact that Right, although C99 -- so far not that much more widely adopted and available than Ada05 -- adds explicitly-sized integers at least for the common cases of 8, 16, 32, 64. (Other values of N are up to the implementation's option, and will probably be rare on common hw.) > the parameter is an address and not a pointer (*), the endianness, and See below. > which bit is being set. As 64-bit architectures become prevalent, the > hidden assumption that C's "unsigned long" is 32 bits wide is more and > more likely to be incorrect. > > (*) consider that when we increment the address by one, it then > references the next byte; whereas if we increment the pointer by one, > it points to the next "unsigned long", i.e. 2, 4 or 8 bytes and not 1 > byte further. C makes no distinction between addresses and pointers, > lacking expressiveness in a crucial area. > Wrong. C, even before C89, does know about pointer targets (strides). Only _very_ early, Bell-Labs-only, pre-K&R1 C that was still in transition from B had pointer === integer. > When calling the subprogram, we get: > > Set_Bit_In_Register (At_Address => To_Address (16#DEADBEEF#)); > (optionally) > versus > > set_bit_in_register (0xDEADBEEF); > The type mismatch is a constraint violation (which must be diagnosed) if the prototype declaration (or definition) is visible, and undefined behavior (~ Ada erroneous, but occurring in many more places, hence not necessarily diagnosed) if not. You _must_ cast: set_bit_in_register ( (/*volatile*/unsigned long *) 0xDEADBEEF ); or (better?) ... ( (my_reg_addr_typedef) 0xDEADBEEF ); (assuming ulong aligned 3 mod 4 even works on your platform ) (You don't actually need the volatile, since the call silently adds it, but it is clearer -- i.e. more expressive -- to have it.) Lack of parameter labelling is a shortcoming, although you can (and people do) smush some of it into the routine name. And tools and/or conventions can be used to find the description or doc when needed. > Again, at the call site, the Ada version gives more information to the > human programmer, i.e. is more expressive. > > Expressiveness is not to be confused with conciseness. Agree there. C does have _some_ expressiveness, where it happened to be necessary or convenient, but not because it was actively sought. - David.Thompson1 at worldnet.att.net