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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: why Ada type casting is different from other languages? newType(value) vs. (newType)value Date: Sun, 13 Jul 2014 12:01:26 +0300 Organization: Tidorum Ltd Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: individual.net 0COQ1qtOS94SD2H23EXzOQB9aRDyxD/Ri2MSzNLk6CS8XRkmIr Cancel-Lock: sha1:YzYLds6Wq/7o253UYwEeH0wI+jw= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: Xref: news.eternal-september.org comp.lang.ada:20905 Date: 2014-07-13T12:01:26+03:00 List-Id: On 14-07-13 04:55 , Nasser M. Abbasi wrote: > I am just wondering what is the rational of Ada choosing to use > type(value) > > vs > (type)value > > to do typecasting. does not type(value) appear as a function call? > as in > > i := float(9); > > vs. > > i := (float) 9; > > Just wondering on this choice and its advantage over the more > common syntax. What do you mean, "common" :-) ? Most programming languages I have seen have the Ada form, "type(value)", although the name of the conversion is not always simply the type-name, but something more specific, at least if the conversion loses information. For example, Fortran 66: - conversion from integer to float: FLOAT(integer_expression) - conversion from float to integer: IFIX(float_expression) Only C and its legitimate and illegitimate offspring and relatives use the form "(type)value", as far as I know. Ranting aside, the C form has the clear disadvantage that one must remember precedence rules to understand what is being converted: is (float)i the same as (float)i + j, or is it the same as (float)(i + j) ? In the Ada form, type(value), the parentheses nicely enclose the value to be converted. Much better IMO. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .