comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
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
Date: 2014-07-13T12:01:26+03:00	[thread overview]
Message-ID: <c2f070Ffne5U1@mid.individual.net> (raw)
In-Reply-To: <lpsoun$5b0$1@speranza.aioe.org>

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
      .      @       .

  parent reply	other threads:[~2014-07-13  9:01 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-13  1:55 why Ada type casting is different from other languages? newType(value) vs. (newType)value Nasser M. Abbasi
2014-07-13  3:01 ` Shark8
2014-07-13  6:26 ` Jeffrey Carter
2014-07-13 14:33   ` Dan'l Miller
2014-07-13  9:01 ` Niklas Holsti [this message]
2014-07-13  9:08   ` Dmitry A. Kazakov
2014-07-13 10:20     ` AdaMagica
2014-07-13 10:24     ` Georg Bauhaus
2014-07-14 23:36       ` Randy Brukardt
2014-07-15 18:42         ` G.B.
2014-07-15 19:14           ` Niklas Holsti
2014-07-15 22:47             ` Georg Bauhaus
2014-07-15 19:19           ` Jeffrey Carter
2014-07-15 23:07             ` Georg Bauhaus
2014-07-15 22:00           ` Randy Brukardt
2014-07-13 14:42 ` Dan'l Miller
2014-07-14 15:25 ` Adam Beneschan
2014-07-14 16:24   ` G.B.
2014-07-14 17:41     ` Simon Wright
2014-07-14 19:41     ` Simon Clubley
2014-07-14 20:51       ` Dan'l Miller
2014-07-14 23:23       ` Randy Brukardt
2014-07-15 19:22 ` Marius Amado-Alves
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox