* 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
* 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