comp.lang.ada
 help / color / mirror / Atom feed
From: "Steve" <nospam_steved94@attbi.com>
Subject: Re: some simple questions
Date: Sat, 22 Feb 2003 16:15:28 GMT
Date: 2003-02-22T16:15:28+00:00	[thread overview]
Message-ID: <AmN5a.219205$Ec4.219339@rwcrnsc52.ops.asp.att.net> (raw)
In-Reply-To: b36b5m$p0i$1@news.rz.uni-karlsruhe.de

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2365 bytes --]

"Daniel Sch�le" <uval@rz.uni-karlsruhe.de> wrote in message
news:b36b5m$p0i$1@news.rz.uni-karlsruhe.de...
> Hi all
>
> I am learning Ada on doing
> I have found some small examples on web and
> now I'm trying to put the mosaic stones together
>
> my questions are
>
> given
>     type pint is access integer;
>     pi: pint:=new integer;
>
> how do I delete the allocated object?
> free(pi);    --doesn't work
> (I'm pretty sure Ada doesn't have Garabge Collector)
>
> is there a syntax available to initialize allocated object (like in C++)?
> int * pi=new int(0);
> now I am doing that this way
> pi.all:=0;
>
If you add:
    procedure free is new ada.unchecked_deallocation( integer, pint );
Then free(pi) works.

Since Ada is a type-safe language, you can't use the same function on any
old type of variable.  Generics are a way of creating generic functions and
procedures where you can specify a specific type by creating an instance of
the function or procedure.

The standard library for Ada includes a generic procedure for deallocating
memory.  You create an instance of the deallocator for your specifc type as
shown above.

Since you're new to Ada, I suggest perusing the standard library of
functions which you'll find at:

  http://www.adaic.org/standards/95lrm/html/RM-A.html

The reference manual isn't very good for learning Ada, but it is a good
reference for the functions in the standard library.

You will find a number of books on Ada at:

http://www.adapower.com/books/


> what is the proper way to assure that pointer points to valid object?

When you declare an access variable in Ada, it is set to null by default.
Usually you can test for a valid pointer by testing for null.

> and last one
> what's "std::system("clear");" translated to Ada
> (OS Linux)
>

I can only guess on this one (you'll probably get an answer from someone
else).
Here's my guess:
  If the profile for system looks something like:
  int system( char *str );

Then in Ada you can use that function by declaring:

  function System( str : Interfaces.C.Strings.Char_Array_Access ) return
integer;
  pragma Import( C, System, "system" );

And then treating the function just as you would any other Ada function.
One of Ada's strong points is interfacing with other languages.

I hope this helps,
Steve
(The Duck)

> sorry if it's faq
>
> Thanks
>
> Daniel
>
>





  parent reply	other threads:[~2003-02-22 16:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-21 22:56 some simple questions Daniel Sch�le
2003-02-22  2:15 ` David C. Hoos, Sr.
2003-02-22  6:29   ` tmoran
2003-02-22 11:22 ` Preben Randhol
2003-02-22 11:57 ` chris.danx
2003-02-22 16:15 ` Steve [this message]
2003-02-22 18:18   ` Jeffrey Carter
replies disabled

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