From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.5-pre1 X-Received: by 2002:a37:a408:: with SMTP id n8mr4842264qke.6.1614876957195; Thu, 04 Mar 2021 08:55:57 -0800 (PST) X-Received: by 2002:a5b:9d2:: with SMTP id y18mr7448367ybq.173.1614876956618; Thu, 04 Mar 2021 08:55:56 -0800 (PST) Path: eternal-september.org!reader02.eternal-september.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 4 Mar 2021 08:55:56 -0800 (PST) In-Reply-To: Injection-Info: google-groups.googlegroups.com; posting-host=146.5.2.231; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 146.5.2.231 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <02709d96-50fe-4e87-bdb5-4f430fa2717an@googlegroups.com> Subject: Re: converting pointer to value From: Shark8 Injection-Date: Thu, 04 Mar 2021 16:55:57 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:61466 List-Id: On Thursday, March 4, 2021 at 8:59:48 AM UTC-7, bj=C3=B6rn lundin wrote: > this code looks like=20 >=20 > type SQLSMALLINT is range -(2 ** 15) .. +(2 ** 15) - 1;=20 > for SQLSMALLINT'Size use 16;=20 >=20 > type SQLRETURN is new SQLSMALLINT;=20 >=20 >=20 > how to get the Pvalue as an SQLRETURN?=20 Ok, in Ada the creation of a new type, even if only deriving it via NEW, ma= kes a type which is incompatible with the old type. Thus you can say TYPE TEMPERATURE IS NEW INTEGER; and TYPE SPEED IS NEW INT= EGER; and values of these types are NOT interchangeable even though both ha= ve the same internal representation and properties that INTEGER does. The w= ay that you can use these different types together is by casting; given X := SPEED :=3D 3; you can say Y : TEMPERATURE :=3D SPEED(X); -- which works b= ecause they have the same internal representation if they did not have the = same representation you would have to use UNCHECKED_CONVERSION. An example where you might need differing representations is modeling the x= 86 -- you could have something like: Type Integer_Register is new Integer; -- IIRC, AX is 16-bits, divided into = bytes AH and AL. Type HL_Byte_Register is record High, Low : Interfaces.Unsigned_8; end record; AX : Integer_Register:=3D 16#EF10#; ... Declare Function Convert is new Ada.Unchecked_Conversion(Integer_Register, HL_Byt= e_Register); Function Convert is new Ada.Unchecked_Conversion(HL_Byte_Register, Intege= r_Register); Temp : HL_Byte_Register :=3D convert( AX ); Begin -- Stuff w/ bytes. AX:=3D Convert( Temp ); End; In the code you present, SQLRETURN derives from SQLSMALLINT, so you can say= SQLSMALLINT( Return_Value )... yes, I know this isn't pvalue as sqlreturn,= we'll get there. >=20 > function SQLParamData (StatementHandle : SQLHSTMT;=20 > pValue : access SQLPOINTER)=20 > return SQLRETURN;=20 >=20 So this returns a number, of the same representation that the 16-bit SQLSMA= LLINT has. > so I get back the column in pValue.=20 > pValue is declared as=20 > Pvalue : aliased Sqlpointer;=20 ... > type SQLPOINTER is private; .... > private > type SQLPOINTER is new System.Storage_Elements.Integer_Address; And here we have SQLPOINTER, which is private, but which is something of th= e same representation that Integer_Address has; let's assume that the ADDRE= SS type is implementation-defined, and a private type. What does this mean? It means that we don't know what the size of ADDRESS (and thus SQLPOINTER) = actually is, but assuming you're on a 32- or 64-bit machine it's likely 2 t= o 4 times as large as the 16-bit SQLSMALLINT-- which is a good indication t= hat a simple UNCHECKED_CONVERSION is the wrong answer. Try looking at the operations which have SQLPOINTER as a parameter/result.