comp.lang.ada
 help / color / mirror / Atom feed
* pointers in Ada
@ 2001-11-14 18:16 lalasa ala
  2001-11-14 18:46 ` Matthew Heaney
  2001-11-14 19:04 ` Preben Randhol
  0 siblings, 2 replies; 10+ messages in thread
From: lalasa ala @ 2001-11-14 18:16 UTC (permalink / raw)
  To: comp.lang.ada



-- 
lalasa ala
lalasa_1999@onebox.com - email
(513) 766-2000 x4491 - voicemail/fax

hi ,
  I have two questions on Ada.
 1)   How are pointers represented in Ada (Ex: if T is a pointer of some
kind R , how is it represented in Ada).

 2)  How are exceptions handled in Ada.

regards,
Lalasa Ala.

__________________________________________________
FREE voicemail, email, and fax...all in one place.
Sign Up Now! http://www.onebox.com




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: pointers in Ada
  2001-11-14 18:16 pointers in Ada lalasa ala
@ 2001-11-14 18:46 ` Matthew Heaney
  2001-11-14 19:04 ` Preben Randhol
  1 sibling, 0 replies; 10+ messages in thread
From: Matthew Heaney @ 2001-11-14 18:46 UTC (permalink / raw)



"lalasa ala" <lalasa_1999@onebox.com> wrote in message
news:mailman.1005761912.32128.comp.lang.ada@ada.eu.org...
>  1)   How are pointers represented in Ada (Ex: if T is a pointer of some
> kind R , how is it represented in Ada).

type T is access all R;

>  2)  How are exceptions handled in Ada.

With an exception handler:

begin
   <do something>;
exception
   when Constraint_Error =>
      <do something>
end;






^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: pointers in Ada
  2001-11-14 18:16 pointers in Ada lalasa ala
  2001-11-14 18:46 ` Matthew Heaney
@ 2001-11-14 19:04 ` Preben Randhol
  2001-11-14 20:10   ` Stephen Leake
  1 sibling, 1 reply; 10+ messages in thread
From: Preben Randhol @ 2001-11-14 19:04 UTC (permalink / raw)


On Wed, 14 Nov 2001 10:16:40 -0800, lalasa ala wrote:
> 
> 
> -- 
> lalasa ala
> lalasa_1999@onebox.com - email
> (513) 766-2000 x4491 - voicemail/fax
> 
> hi ,

Hi. Please type your message *above* your signature.

>   I have two questions on Ada.
>  1)   How are pointers represented in Ada (Ex: if T is a pointer of some
> kind R , how is it represented in Ada).
 
http://www.it.bton.ac.uk/staff/je/adacraft/ch11.htm

>  2)  How are exceptions handled in Ada.

http://www.it.bton.ac.uk/staff/je/adacraft/ch03.htm#3.9
http://www.it.bton.ac.uk/staff/je/adacraft/ch07.htm

Preben
-- 
                 �For me, Ada95 puts back the joy in programming.�



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: pointers in Ada
  2001-11-14 19:04 ` Preben Randhol
@ 2001-11-14 20:10   ` Stephen Leake
  2001-11-15  7:32     ` Preben Randhol
  0 siblings, 1 reply; 10+ messages in thread
From: Stephen Leake @ 2001-11-14 20:10 UTC (permalink / raw)



Now this is cool; to be able to point a newbie to an actual textbook!


Preben Randhol <randhol+abuse@pvv.org> writes:

> On Wed, 14 Nov 2001 10:16:40 -0800, lalasa ala wrote:
> 
> >   I have two questions on Ada.
> >  1)   How are pointers represented in Ada (Ex: if T is a pointer of some
> > kind R , how is it represented in Ada).
>  
> http://www.it.bton.ac.uk/staff/je/adacraft/ch11.htm
> 
> >  2)  How are exceptions handled in Ada.
> 
> http://www.it.bton.ac.uk/staff/je/adacraft/ch03.htm#3.9
> http://www.it.bton.ac.uk/staff/je/adacraft/ch07.htm
> 
> Preben
> -- 
>                  �For me, Ada95 puts back the joy in programming.�

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: pointers in Ada
  2001-11-14 20:10   ` Stephen Leake
@ 2001-11-15  7:32     ` Preben Randhol
  2001-11-15 14:00       ` David Botton
  0 siblings, 1 reply; 10+ messages in thread
From: Preben Randhol @ 2001-11-15  7:32 UTC (permalink / raw)


On 14 Nov 2001 15:10:09 -0500, Stephen Leake wrote:

> Now this is cool; to be able to point a newbie to an actual textbook!

Yes :-) and now there are four books online (one have been online all
its time though; �The Big Online Book of Linux Ada Programming�).

Preben



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: pointers in Ada
  2001-11-15  7:32     ` Preben Randhol
@ 2001-11-15 14:00       ` David Botton
  0 siblings, 0 replies; 10+ messages in thread
From: David Botton @ 2001-11-15 14:00 UTC (permalink / raw)


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

I know of at least seven books on line for Ada.

http://www.adapower.com/learn


Ada Distilled
Ada 95: The Craft of Object-Oriented Programming
Object Oriented Programming in Ada 95
The Big Online Book of Linux Ada Programming
Ada in Action
Introducing Ada 95
LAW - Lear Ada on the Web = Ada: A Developmental Approach

The top 3 are new, but the other four have been with us for some time.

BTW, if you count the RM, Rationale and Style Guide that makes _10_ books
on-line

Plus we have Quick Reference Cards and more :-)
(http://www.adapower.com/ref)


David Botton



"Preben Randhol" <randhol+abuse@pvv.org> wrote in message
news:slrn9v6vpi.h6.randhol+abuse@kiuk0156.chembio.ntnu.no...
> On 14 Nov 2001 15:10:09 -0500, Stephen Leake wrote:
>
> > Now this is cool; to be able to point a newbie to an actual textbook!
>
> Yes :-) and now there are four books online (one have been online all
> its time though; �The Big Online Book of Linux Ada Programming�).
>
> Preben





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Pointers in Ada
@ 2005-03-04 12:25 Sebastian
  2005-03-04 13:03 ` Adrien Plisson
  2005-03-04 18:26 ` Jeffrey Carter
  0 siblings, 2 replies; 10+ messages in thread
From: Sebastian @ 2005-03-04 12:25 UTC (permalink / raw)


Hi I have a question about how to initliaze a message that I want to
send. The code below shows my types and all, but my concern is the
syntax, how do I write the code that initializes the message so that I
can call the Put_Message procedure?


-- This is MDP_LLD package....
package Mdp_Lld;
  type Message_Header is
     record
       Word_Count              : Byte;
       Command_Id              : Byte;
     end record;

     subtype Mdp_Message_Data is Byte(1..500);

     type A_Mdp_Message is
        record
          Header : aliased Message_Header;
          Data   : aliased Mdp_Message_Data;
        end record;

     type Driver_Msg_Ptr_Type is access all A_MDP_Message;

     procedure Put_Message
        (Msg_Buffer_Ptr : in out Client_Msg_Ptr_Type;
);

private

  type Client_Msg_Ptr_Type is new Driver_Msg_Ptr_Type;

end Mdp_Lld;



-- this is another file
with Mdp_lld; use Mdp_lld;

procedure Test_Driver is
   Output_Msg      : Mdp_Lld.A_Mdp_Message;
   Mdp_Msg_Ptr_Out : MDP_LLD.Client_Msg_Ptr_Type;
begin

   -- Initialize output message
   Output_Msg.Header.Word_Count  := 32; 
   Output_Msg.Header.Command_Id  := 4; 
 
   -- How do I Initialize my message to send?
   Mdp_Msg_Ptr_Out'access := Output_Msg; --this does not work?
   Mdp_Msg_Ptr_Out.all    := Output_Msg; --this does not work?

end;



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Pointers in Ada
  2005-03-04 12:25 Pointers " Sebastian
@ 2005-03-04 13:03 ` Adrien Plisson
  2005-03-04 18:26 ` Jeffrey Carter
  1 sibling, 0 replies; 10+ messages in thread
From: Adrien Plisson @ 2005-03-04 13:03 UTC (permalink / raw)


Sebastian wrote:
>    -- How do I Initialize my message to send?
>    Mdp_Msg_Ptr_Out'access := Output_Msg; --this does not work?
>    Mdp_Msg_Ptr_Out.all    := Output_Msg; --this does not work?

well, it seems you are having a lot of troubles with pointers/access 
types.

what you want to do is setting Mdp_Msg_Ptr_Out to a value which will 
point to Output_Msg.

you wrote:
- first line: (vaguely) setting the address of Mdp_Msg_Ptr_Out to be 
the same as the address of Output_Msg.
- second line: copy the content of Ouput_Msg at the address pointed to 
by Mdp_Msg_Ptr_Out, which is uninitialized

reverse the problem !
Mdp_Msg_Ptr_Out := Output_Msg'Access;

note that this will need Output_Msg to be declared as aliased... also 
MDP_LLD.Client_Msg_Ptr_Type needs to be visible, and in your sample, 
it is private. (there are also other solutions to your problem).

I suggest you grab your favorite book on Ada and re-read the chapter 
concerning access types. don't try to do something too elaborated at 
first.

-- 
rien



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Pointers in Ada
  2005-03-04 12:25 Pointers " Sebastian
  2005-03-04 13:03 ` Adrien Plisson
@ 2005-03-04 18:26 ` Jeffrey Carter
  2005-03-05 15:47   ` Sebastian
  1 sibling, 1 reply; 10+ messages in thread
From: Jeffrey Carter @ 2005-03-04 18:26 UTC (permalink / raw)


Sebastian wrote:

> package Mdp_Lld;
>   type Message_Header is
>      record
>        Word_Count              : Byte;
>        Command_Id              : Byte;
>      end record;
> 
>      subtype Mdp_Message_Data is Byte(1..500);
> 
>      type A_Mdp_Message is
>         record
>           Header : aliased Message_Header;
>           Data   : aliased Mdp_Message_Data;
>         end record;
> 
>      type Driver_Msg_Ptr_Type is access all A_MDP_Message;
> 
>      procedure Put_Message
>         (Msg_Buffer_Ptr : in out Client_Msg_Ptr_Type;
> );

As you're no doubt aware, this won't compile. In addition to the syntax 
error in the declaration of Put_Message, Client_Msg_Ptr_Type has not 
been declared.

Before we can answer your questions, we need to know why you're using 
pointers. What wrong with

procedure Put_Message (Message : in An_Mdp_Message);

?

In Ada pointers are needed far more rarely than in some other languages. 
Since you're not building a dynamic data structure, it's likely that you 
don't need them. If you really do need them, it's probably a better 
design to hide them from the clients of the package. That way you can 
localize the memory management to your package.

-- 
Jeff Carter
"Saving keystrokes is the job of the text editor,
not the programming language."
Preben Randhol
64



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Pointers in Ada
  2005-03-04 18:26 ` Jeffrey Carter
@ 2005-03-05 15:47   ` Sebastian
  0 siblings, 0 replies; 10+ messages in thread
From: Sebastian @ 2005-03-05 15:47 UTC (permalink / raw)


Jeffrey Carter <spam@spam.com> wrote in message news:<0L1Wd.824$oO4.709@newsread3.news.pas.earthlink.net>...
> Sebastian wrote:
> 
> > package Mdp_Lld;
> >   type Message_Header is
> >      record
> >        Word_Count              : Byte;
> >        Command_Id              : Byte;
> >      end record;
> > 
> >      subtype Mdp_Message_Data is Byte(1..500);
> > 
> >      type A_Mdp_Message is
> >         record
> >           Header : aliased Message_Header;
> >           Data   : aliased Mdp_Message_Data;
> >         end record;
> > 
> >      type Driver_Msg_Ptr_Type is access all A_MDP_Message;
> > 
> >      procedure Put_Message
> >         (Msg_Buffer_Ptr : in out Client_Msg_Ptr_Type;
> > );
> 
> As you're no doubt aware, this won't compile. In addition to the syntax 
> error in the declaration of Put_Message, Client_Msg_Ptr_Type has not 
> been declared.
> 
> Before we can answer your questions, we need to know why you're using 
> pointers. What wrong with
> 
> procedure Put_Message (Message : in An_Mdp_Message);
> 
> ?
> 
> In Ada pointers are needed far more rarely than in some other languages. 
> Since you're not building a dynamic data structure, it's likely that you 
> don't need them. If you really do need them, it's probably a better 
> design to hide them from the clients of the package. That way you can 
> localize the memory management to your package.

Hi everybody

thanks for your answers. First, I have not written the code myself it
is a UDP/IP stack that I found as a open source. I would not use
pointers myself thats why I'm havning problems knowing how to
initialize them;) Anyway, sorry that the code does not compile but I
extracted it from the files and "tweaked" it to fit the forum.
Soo, in order to create a message and send it using Put_Message I have
to create a variable of the private type Client_Msg_Ptr_Type in "my
calling source code file" BUT in order to do that the calling code
must be within a child package to the Mdp_lld package otherwise the
private type is not visable, or am I missing something here? Also the
Outmessage has to be aliased and I have to write the code like:
My_Msg_Ptr := Outmessage'Access;

Will this work? Well I will try it on monday...I'll let you know..

Thanks,

Sebastian



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2005-03-05 15:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-14 18:16 pointers in Ada lalasa ala
2001-11-14 18:46 ` Matthew Heaney
2001-11-14 19:04 ` Preben Randhol
2001-11-14 20:10   ` Stephen Leake
2001-11-15  7:32     ` Preben Randhol
2001-11-15 14:00       ` David Botton
  -- strict thread matches above, loose matches on Subject: below --
2005-03-04 12:25 Pointers " Sebastian
2005-03-04 13:03 ` Adrien Plisson
2005-03-04 18:26 ` Jeffrey Carter
2005-03-05 15:47   ` Sebastian

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