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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1901f265c928a511 X-Google-Attributes: gid103376,public Path: controlnews3.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsread.com!newsstand.newsread.com!POSTED.monger.newsread.com!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Typing in Ada From: "Peter C. Chapin" References: Organization: Kelsey Mountain Software Message-ID: User-Agent: Xnews/5.04.25 Date: Wed, 02 Jun 2004 10:53:05 GMT NNTP-Posting-Host: 216.114.169.47 X-Complaints-To: Abuse Role , We Care X-Trace: monger.newsread.com 1086173585 216.114.169.47 (Wed, 02 Jun 2004 06:53:05 EDT) NNTP-Posting-Date: Wed, 02 Jun 2004 06:53:05 EDT Xref: controlnews3.google.com comp.lang.ada:1017 Date: 2004-06-02T10:53:05+00:00 List-Id: Jeffrey Carter wrote in news:Q4avc.18446$Tn6.11146@newsread1.news.pas.earthlink.net: >> This isn't an entirely fair comparison because in C, typedef doesn't >> introduce a new type it simply creates a new name for an existing type. >> In Ada, it would be more similar to using a subtype, perhaps. Something >> like > > The ability to > define new numeric types is a way that Ada allows the compiler to detect > errors that C lacks. Thus, the example is a perfectly good example of > Ada being more strongly typed than C, and a fair comparison of the > strength of typing in the 2 languages. I guess my point was that in C typedef does not even attempt to define a new type so comparing it to Ada's 'type' declaration seems unfair. For example if you replace the type declarations in the OP's example with unconstrained subtype declarations, the OP's Ada program compiles with no complaints just like the the example C program using typedef does. Now in C there *is* a mechanism for creating new types... it's just that typedef isn't it. Thus it would be more appropriate to compare an Ada program that introduces a new type that is a numeric range to a C program that implements numeric ranges as structs. There is no doubt that the Ada way of creating ranged types is easier and cleaner than any kind of "equivalent" solution in plain C might be. On the other hand, I'm sure C++ could do a much better job of emulating the Ada solution by using templates and overloaded operators. In any case, the OP's example didn't seem like a good example of how Ada is more strongly typed than C. It is certainly true that Ada does not do automatic type conversions the way C does, but the OP's example doesn't illustrate that point. In contrast, when I think about a weakly typed language I think about languages like AWK, the shell scripting languages, or perhaps Perl... where the type of a variable shifts around depending on how it is used. For example: #!/bin/bash COUNT=1 echo "COUNT is now $COUNT" # Treat COUNT as a string COUNT=$(($COUNT + 1)) # Treat COUNT as a number echo "COUNT is now $COUNT" Peter