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: Tue, 15 Jul 2014 22:14:31 +0300
Date: 2014-07-15T22:14:31+03:00	[thread overview]
Message-ID: <c2lcsmFqptsU1@mid.individual.net> (raw)
In-Reply-To: <lq3slq$n75$1@dont-email.me>

On 14-07-15 21:42 , G.B. wrote:

> And later, is it really good or bad if it takes years or not
> to be competent enough to understand
> 
>   ptrdiff_t x = *(ptrdiff_t*)main;
> 
> vs
> 
>   X : Integer_Address := To_Integer (Main'Address);
> 
> if they are comparable?

Aah... they are *not* "comparable", if by that you mean "equivalent".
The first (C) declaration interprets the entry address of "main" as a
pointer to a ptrdiff_t, and then dereferences that pointer to read this
putative ptrdiff_t value and store it in x. In other words, x will
contain bits from the initial instructions of "main".

The second (Ada) declaration simply converts the entry address of "Main"
to an Integer_Address. It does not read anything from the instructions
in Main.

Perhaps I misunderstood your point?

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
      .      @       .

  reply	other threads:[~2014-07-15 19:14 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
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 [this message]
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