comp.lang.ada
 help / color / mirror / Atom feed
* newbie q: access types getting address
@ 2001-06-13 23:24 Jesse Farmer
  2001-06-13 23:56 ` James Rogers
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jesse Farmer @ 2001-06-13 23:24 UTC (permalink / raw)


Please pardon my ignorance, but I have not been able to find how to do this
on the web.

I want to get the address of a particular object that is getting passed into
a function.  How can I do this?
Also, how can I get the address of some arbitrary element of an array?

Essentially, I want the return value of the following c++ statements:

return &Obj;
and
return &Array[5];

I understand that having pointers all over the place is somewhat discouraged
in Ada, but this is for a Windows API call binding.  Sorry if this is
obvious and I have overlooked it.  Any informative responses would be
greatly appreciated.  Thanks for your time + bandwidth.

-Jesse Farmer
University of Cincinnati





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

* Re: newbie q: access types getting address
  2001-06-13 23:24 newbie q: access types getting address Jesse Farmer
@ 2001-06-13 23:56 ` James Rogers
  2001-06-14  1:49 ` tmoran
  2001-06-14 13:52 ` Jesse Farmer
  2 siblings, 0 replies; 4+ messages in thread
From: James Rogers @ 2001-06-13 23:56 UTC (permalink / raw)


The address of an object can be identified as a System.Address type.

Read the Ada LRM section 13.7.2 for details.

What you probably really want to do is convert to or from the
System.Address type from an Ada access type. This can be done using
the System.Address_To_Access_Conversions generic package.
Once you convert from the C++ &Array[5] to an access to an Ada
array, you can access the individual elements using normal Ada
indexing.

Jim Rogers
Colorado Springs, Colorado USA

Jesse Farmer wrote:
> 
> Please pardon my ignorance, but I have not been able to find how to do this
> on the web.
> 
> I want to get the address of a particular object that is getting passed into
> a function.  How can I do this?
> Also, how can I get the address of some arbitrary element of an array?
> 
> Essentially, I want the return value of the following c++ statements:
> 
> return &Obj;
> and
> return &Array[5];
> 
> I understand that having pointers all over the place is somewhat discouraged
> in Ada, but this is for a Windows API call binding.  Sorry if this is
> obvious and I have overlooked it.  Any informative responses would be
> greatly appreciated.  Thanks for your time + bandwidth.
> 
> -Jesse Farmer
> University of Cincinnati



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

* Re: newbie q: access types getting address
  2001-06-13 23:24 newbie q: access types getting address Jesse Farmer
  2001-06-13 23:56 ` James Rogers
@ 2001-06-14  1:49 ` tmoran
  2001-06-14 13:52 ` Jesse Farmer
  2 siblings, 0 replies; 4+ messages in thread
From: tmoran @ 2001-06-14  1:49 UTC (permalink / raw)


>I want to get the address of a particular object that is getting passed into
>...
>in Ada, but this is for a Windows API call binding.  Sorry if this is
  For a Windows binding you almost certainly want 'access, not 'address.
(Though System.Address_To_Access_Conversions can interconvert the two.)

>return &Obj;
>and
>return &Array[5];
 return Obj'access;
 return Array(5)'access;
If you get accessibility level errors, the compiler is telling you
that you are creating a pointer that may outlive what it's pointing to.
If you're sure what you are doing is safe, you can
  return Obj'unchecked_access;
etc.  You'll see a lot of that in Ada code accessing Windows' API.



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

* Re: newbie q: access types getting address
  2001-06-13 23:24 newbie q: access types getting address Jesse Farmer
  2001-06-13 23:56 ` James Rogers
  2001-06-14  1:49 ` tmoran
@ 2001-06-14 13:52 ` Jesse Farmer
  2 siblings, 0 replies; 4+ messages in thread
From: Jesse Farmer @ 2001-06-14 13:52 UTC (permalink / raw)


thanks for the info
Its really appreciated.

-Jesse Farmer





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

end of thread, other threads:[~2001-06-14 13:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-13 23:24 newbie q: access types getting address Jesse Farmer
2001-06-13 23:56 ` James Rogers
2001-06-14  1:49 ` tmoran
2001-06-14 13:52 ` Jesse Farmer

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