comp.lang.ada
 help / color / mirror / Atom feed
From: arny@cbnewsl.ATT.COM (arny.b.engelson)
Subject: Re: Questions on Ada...
Date: 3 Jul 89 13:51:02 GMT	[thread overview]
Message-ID: <979@cbnewsl.ATT.COM> (raw)
In-Reply-To: 3034@wpi.wpi.edu

In article <3034@wpi.wpi.edu> tfrancis@wpi.wpi.edu (Krishan M Nainani) writes:
>
>(1)	Is there any way to mimic the C pre-processor commands in Ada.
>	For example, is it possible to mimic:
>	#ifdef TEMP
>	...
>	#endif

Well, sort of.  It is really outside of the language, but you can use the
same C pre-processor commands, and simply run the code through the C pre-
processor before running it through the Ada compiler.  I have actually seen
people do this, and it has worked quite well.  It may not be so hot from
a Configuration Management point of view, and will get some Ada purists up
in arms, but it works.

On some compilers you may be able to achieve this using Pragmas, keeping
the code true Ada, but unusable on other systems.


>(2)	Is it possible to copy sections of memory regardless of its
>	contents from one type to another. For example, in C:
>
>	atype : *ptr1; btype : *ptr2; /* atype and btype are different */
>	for (i=0;i<123;i++)  *ptr1++ = *ptr2++; 

There is more than one way to do this.  One alternative is to use overlays.
Simply declare an integer array of the proper length, use an address clause
to overlay it at the location occupied by the structure you are copying
from, and copy it to an integer array overlayed at the destination address.
Another alternative is to use unchecked conversion from one type to another.
Again, the Ada purists will be up in arms (overlays are officially erroneous),
but the concept is very useful in some situations.  BTW, erroneous doesn't
mean it won't work, but it does mean you had better be sure you know what you
are doing.

>Thanx in advance.
You're welcome.

>Krishan Nainani.	reply-to: tfrancis@wpi.wpi.edu

  - Arny Engelson   wayback!arny

  reply	other threads:[~1989-07-03 13:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1989-06-29  3:33 Questions on Ada Krishan M Nainani
1989-07-03 13:51 ` arny.b.engelson [this message]
1989-07-06 19:02   ` Vladimir G. Ivanovic
1989-07-11 19:41     ` arny.b.engelson
1989-07-05 23:42 ` John Rogers
replies disabled

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