comp.lang.ada
 help / color / mirror / Atom feed
From: zhenglonggen <zhenglonggen@163.net>
To: comp.lang.ada@ada-france.org
Subject: Re: Access type conversions, how?
Date: Tue, 13 Apr 2004 22:57:12 +0800
Date: 2004-04-13T22:57:12+08:00	[thread overview]
Message-ID: <mailman.249.1081893601.327.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: pan.2004.04.13.00.32.33.603741@n_o_p_o_r_k_a_n_d_h_a_m.abyss2.demon.co.uk

Luke A. Guest wrote:

 >Hi,
 >
 >We have the following in our GL package:
 >
 >package C renames Interfaces.C;
 >...
 >type GLfloat      is new C.C_float;
 >...
 >type GLfloatPtr   is access all GLfloat;
 >...
 >procedure glMultMatrixf(M : in GLfloatPtr);
 >
 >Now, in my code, I've created a Matrix package which has as it's type:
 >
 >type Object is array(Integer range 0 .. 15) of aliased Float;
 >Now, I've made it aliased because I want to pass this to glMultMatrixf,
 >but for some reason I cannot work out exactly how to do it.
 >
 >I've tried all sorts, like:
 >
 >GL.glMultMatrixf(M(M'First)'Unchecked_Access); -- Wrong type
 >
The following code works:


with Ada.Text_Io;
use Ada.Text_Io;
with System;
use System;
with Interfaces.C;
use Interfaces.C;
procedure Test_access2address is
    type GLFloat is new C_Float;
    type GLFloat_Ptr is access all GLFloat;
    type Object is array(0..15) of aliased GLFloat;
    type Object_Ptr is access all Object;
    function Access2address(An_Object_Ptr:Object_Ptr) return GLFloat_Ptr
    is
       A_GLfloat:aliased GLFloat;
       for A_GLFloat'Address use An_Object_Ptr(1)'Address;
    begin
       return A_GLfloat'Unchecked_Access;
    end;
    procedure Test(A_Float:GLFloat_Ptr) is
    begin
       Put_Line("the first element is "&GLfloat'Image(A_Float.all));
    end;
    My_Object:aliased Object;
begin
    My_Object(1):=0.001;
    Test(Access2address(My_Object'Access));
end;








  parent reply	other threads:[~2004-04-13 14:57 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-13  0:32 Access type conversions, how? Luke A. Guest
2004-04-13  1:25 ` Randy Brukardt
2004-04-13  8:08   ` Luke A. Guest
2004-04-13 15:11     ` chris
2004-04-13 16:01       ` Luke Guest
2004-04-13 17:54         ` chris
2004-04-13 19:31           ` Luke A. Guest
2004-04-13 22:51             ` Luke A. Guest
2004-04-13 21:59               ` Lutz Donnerhacke
2004-04-14 11:53                 ` Luke Guest
2004-04-14 12:07                   ` Lutz Donnerhacke
2004-04-14 13:36             ` Robert I. Eachus
2004-04-14 17:37               ` Jeffrey Carter
2004-04-13 14:57 ` zhenglonggen [this message]
2004-04-14  7:45   ` Martin Dowie
2004-04-14 11:49     ` Luke Guest
replies disabled

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