* Put the access value @ 2020-04-14 7:15 ldries46 2020-04-14 7:42 ` J-P. Rosen 2020-04-14 11:05 ` Jeffrey R. Carter 0 siblings, 2 replies; 17+ messages in thread From: ldries46 @ 2020-04-14 7:15 UTC (permalink / raw) I have a situation in which it is not practical to use the debugging possibilities of GNAT GPS. Instead I want to use the Put procedure to show certain values. Normally that is no such a program with the Predifined Language attributes (mostly with the 'image attribute). Now I have the following: type Buffer_Pointer is limited private; type Block_Buffer is record nr : integer; buf : Item; previous : Buffer_Pointer := null; next : Buffer_Pointer := null; end record; El : Buffer_Pointer := LastBuffer; El1 : Buffer_Pointer; I just want to see if the routing of thedifferent Buffer_Pointer's is correct so I thought Buffer_Pointer'Image(El) would show the value of The Pointer El f.i. ?x000000 for null or even the simpel decimal value 0. This construction creates a failure during compiling. Should I use another attribute or some other construction? ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Put the access value 2020-04-14 7:15 Put the access value ldries46 @ 2020-04-14 7:42 ` J-P. Rosen 2020-04-18 15:08 ` Oliver Kellogg 2020-04-20 23:02 ` Robert A Duff 2020-04-14 11:05 ` Jeffrey R. Carter 1 sibling, 2 replies; 17+ messages in thread From: J-P. Rosen @ 2020-04-14 7:42 UTC (permalink / raw) Le 14/04/2020 à 09:15, ldries46 a écrit : > I just want to see if the routing of thedifferent Buffer_Pointer's is > correct so I thought Buffer_Pointer'Image(El) would show the value of > The Pointer El f.i. ?x000000 for null or even the simpel decimal value 0. > > This construction creates a failure during compiling. > Should I use another attribute or some other construction? In Ada, a pointer is not an integer and has no 'Image attribute. A pointer is not an address either. Of course, for debugging you can indulge your self to constructs that would be thrown at for long term maintenance. So... 1) Use Unchecked_Conversion to convert it to an appropriate integer type 2) use package Address_To_Access conversion to convert your pointer to an address, then System.Storage_Elements.To_Integer to convert the address to Integer_Address, which is an integer type. -- J-P. Rosen Adalog 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00 http://www.adalog.fr ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Put the access value 2020-04-14 7:42 ` J-P. Rosen @ 2020-04-18 15:08 ` Oliver Kellogg 2020-04-20 23:02 ` Robert A Duff 1 sibling, 0 replies; 17+ messages in thread From: Oliver Kellogg @ 2020-04-18 15:08 UTC (permalink / raw) On Tuesday, April 14, 2020 at 9:42:56 AM UTC+2, J-P. Rosen wrote: > Le 14/04/2020 à 09:15, ldries46 a écrit : > > [...] > In Ada, a pointer is not an integer and has no 'Image attribute. A > pointer is not an address either. Of course, for debugging you can > indulge your self to constructs that would be thrown at for long term > maintenance. So... > > 1) Use Unchecked_Conversion to convert it to an appropriate integer type > > 2) use package Address_To_Access conversion to convert your pointer to > an address, then System.Storage_Elements.To_Integer to convert the > address to Integer_Address, which is an integer type. There's also the sledgehammer-to-crack-a-nut solution: https://github.com/persan/auto-io-gen - Oliver ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Put the access value 2020-04-14 7:42 ` J-P. Rosen 2020-04-18 15:08 ` Oliver Kellogg @ 2020-04-20 23:02 ` Robert A Duff 2020-04-21 7:07 ` briot.emmanuel 1 sibling, 1 reply; 17+ messages in thread From: Robert A Duff @ 2020-04-20 23:02 UTC (permalink / raw) "J-P. Rosen" <rosen@adalog.fr> writes: > In Ada, a pointer is not an integer and has no 'Image attribute. Sure it does. ;-) So do records and everything else. See AI12-0020-1 (don't pay attention to details; they're changing). I implemented that recently, so the latest development version of GNAT has it. This program: with Ada.Strings.Text_Output.Formatting; use Ada.Strings.Text_Output; procedure Access_Image is type R is record This : Integer; That : String (1..10); end record; type A is access all R; X : A := new R'(This => 123, That => "helloworld"); begin Formatting.Put ("\1, \2\n", X'Image, X.all'Image); end Access_Image; prints: (access 162b740), (this => 123, that => "helloworld") > 1) Use Unchecked_Conversion to convert it to an appropriate integer type > > 2) use package Address_To_Access conversion to convert your pointer to > an address, then System.Storage_Elements.To_Integer to convert the > address to Integer_Address, which is an integer type. Right, these are good workarounds if you don't have the latest version. - Bob ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Put the access value 2020-04-20 23:02 ` Robert A Duff @ 2020-04-21 7:07 ` briot.emmanuel 2020-04-21 22:29 ` Robert A Duff 0 siblings, 1 reply; 17+ messages in thread From: briot.emmanuel @ 2020-04-21 7:07 UTC (permalink / raw) > > In Ada, a pointer is not an integer and has no 'Image attribute. > > Sure it does. ;-) Hey, that's GNAT specific again, no other compiler implements that yet ! :-) This is very nice, indeed. We (and I would guess a lot of others) have come up with some code-generation scheme to generate those output routines for our types. We use libadalang for now (distributed with GNAT). Although our home-made solution is mode flexible (with binary or text output, for instance, as well as backward compatibility with older type definitions), having this service part of the compiler definitely removes some of the needs for custom frameworks... Some of the difficulties I had in implementing the code generation was for generics and their instances, or class-wide types. Are those handled natively by the compiler now, when using 'Image ? Thanks for letting us know Bob ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Put the access value 2020-04-21 7:07 ` briot.emmanuel @ 2020-04-21 22:29 ` Robert A Duff 0 siblings, 0 replies; 17+ messages in thread From: Robert A Duff @ 2020-04-21 22:29 UTC (permalink / raw) briot.emmanuel@gmail.com writes: > Some of the difficulties I had in implementing the code generation was > for generics and their instances, or class-wide types. Are those handled > natively > by the compiler now, when using 'Image ? Put_Image works for types in instances of generics. It does not work for class-wide types -- still working on that. > Thanks for letting us know Bob You're welcome. - Bob ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Put the access value 2020-04-14 7:15 Put the access value ldries46 2020-04-14 7:42 ` J-P. Rosen @ 2020-04-14 11:05 ` Jeffrey R. Carter 2020-04-14 12:09 ` ldries46 1 sibling, 1 reply; 17+ messages in thread From: Jeffrey R. Carter @ 2020-04-14 11:05 UTC (permalink / raw) On 4/14/20 9:15 AM, ldries46 wrote: > > type Buffer_Pointer is limited private; > > type Block_Buffer is record > nr : integer; > buf : Item; > previous : Buffer_Pointer := null; > next : Buffer_Pointer := null; > end record; > > El : Buffer_Pointer := LastBuffer; > El1 : Buffer_Pointer; > > I just want to see if the routing of thedifferent Buffer_Pointer's is correct so > I thought Buffer_Pointer'Image(El) would show the value of The Pointer El f.i. > ?x000000 for null or even the simpel decimal value 0. 1. There are no access types in this code. The declaration of type Block_Buffer is invalid because null cannot be a valid visible value of type Buffer_Pointer II. Assuming the full type of Buffer_Pointer is an access type, and the declaration of Block_Buffer can see the full type, it appears you are creating a linked list. Why not use Ada.Containers.Doubly_Linked_Lists? C. Assuming you're still going to use access types, why are you interested in the internal representation of access values? These will probably appear to be random values that provide no information, except perhaps whether the value is null iv. If you're only interested in whether an access value is null or not, this can be better determined without showing the internal representation: "El is null " & Boolean'Image (El = null) "El is " & (if El = null then "" else "not ") & "null" -- Jeff Carter "Your mother was a hamster and your father smelt of elderberries." Monty Python & the Holy Grail 06 ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Put the access value 2020-04-14 11:05 ` Jeffrey R. Carter @ 2020-04-14 12:09 ` ldries46 2020-04-15 7:20 ` briot.emmanuel 0 siblings, 1 reply; 17+ messages in thread From: ldries46 @ 2020-04-14 12:09 UTC (permalink / raw) Op 14-4-2020 om 13:05 schreef Jeffrey R. Carter: > On 4/14/20 9:15 AM, ldries46 wrote: >> >> type Buffer_Pointer is limited private; >> >> type Block_Buffer is record >> nr : integer; >> buf : Item; >> previous : Buffer_Pointer := null; >> next : Buffer_Pointer := null; >> end record; >> >> El : Buffer_Pointer := LastBuffer; >> El1 : Buffer_Pointer; >> >> I just want to see if the routing of thedifferent Buffer_Pointer's is >> correct so I thought Buffer_Pointer'Image(El) would show the value of >> The Pointer El f.i. ?x000000 for null or even the simpel decimal >> value 0. > > 1. There are no access types in this code. The declaration of type > Block_Buffer is invalid because null cannot be a valid visible value > of type Buffer_Pointer > > II. Assuming the full type of Buffer_Pointer is an access type, and > the declaration of Block_Buffer can see the full type, it appears you > are creating a linked list. Why not use > Ada.Containers.Doubly_Linked_Lists? > > C. Assuming you're still going to use access types, why are you > interested in the internal representation of access values? These will > probably appear to be random values that provide no information, > except perhaps whether the value is null > > iv. If you're only interested in whether an access value is null or > not, this can be better determined without showing the internal > representation: > > "El is null " & Boolean'Image (El = null) > > "El is " & (if El = null then "" else "not ") & "null" > Thanks to mr J.P Rosen this worked and I have checked a Buffer random Buffer insert routinethat looked like it didn't work but I could see that it in fact worked correctly. I used the Ada Unchecked conversion. Mr Carter the Buffer_Pointer is an access declaration which was limited private. And I just had presented it for the possibility that the problem should be created by its limited private pro ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Put the access value 2020-04-14 12:09 ` ldries46 @ 2020-04-15 7:20 ` briot.emmanuel 2020-04-15 8:02 ` AdaMagica 0 siblings, 1 reply; 17+ messages in thread From: briot.emmanuel @ 2020-04-15 7:20 UTC (permalink / raw) The approach I tend to use is using `System.Address_Image`: El : Buffer_Pointer := LastBuffer; ... if El /= null then Ada.Text_IO.Put_Line (System.Address_Image (El.all'Address)); end if; or if this is for slightly longer term function Convert is new Ada.Unchecked_Conversion (Buffer_Pointer, System.Address); Ada.Text_IO.Put_Line (System.Address_Image (Convert (El)); This is really just for quick debugging, and the code is never (really, I swear) committed... Otherwise, I would go to the trouble of creating an `Image` function and use that ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Put the access value 2020-04-15 7:20 ` briot.emmanuel @ 2020-04-15 8:02 ` AdaMagica 2020-04-15 8:51 ` J-P. Rosen 2020-04-17 14:20 ` Björn Lundin 0 siblings, 2 replies; 17+ messages in thread From: AdaMagica @ 2020-04-15 8:02 UTC (permalink / raw) Am Mittwoch, 15. April 2020 09:20:33 UTC+2 schrieb briot....@gmail.com: > The approach I tend to use is using `System.Address_Image`: This is not in the RM. It must be GNAT specific, which you should have said. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Put the access value 2020-04-15 8:02 ` AdaMagica @ 2020-04-15 8:51 ` J-P. Rosen 2020-04-15 16:23 ` AdaMagica 2020-04-17 14:20 ` Björn Lundin 1 sibling, 1 reply; 17+ messages in thread From: J-P. Rosen @ 2020-04-15 8:51 UTC (permalink / raw) Le 15/04/2020 à 10:02, AdaMagica a écrit : > Am Mittwoch, 15. April 2020 09:20:33 UTC+2 schrieb briot....@gmail.com: >> The approach I tend to use is using `System.Address_Image`: > > This is not in the RM. It must be GNAT specific, which you should have said. > True. But for quick debugging, you don't care about portability... -- J-P. Rosen Adalog 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00 http://www.adalog.fr ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Put the access value 2020-04-15 8:51 ` J-P. Rosen @ 2020-04-15 16:23 ` AdaMagica 0 siblings, 0 replies; 17+ messages in thread From: AdaMagica @ 2020-04-15 16:23 UTC (permalink / raw) Am Mittwoch, 15. April 2020 10:51:28 UTC+2 schrieb J-P. Rosen: > Le 15/04/2020 à 10:02, AdaMagica a écrit : > > Am Mittwoch, 15. April 2020 09:20:33 UTC+2 schrieb briot....@gmail.com: > >> The approach I tend to use is using `System.Address_Image`: > > > > This is not in the RM. It must be GNAT specific, which you should have said. > > > True. But for quick debugging, you don't care about portability... True, but there might be some people here, a remote possibility, of utmost improbability, not using GNAT. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Put the access value 2020-04-15 8:02 ` AdaMagica 2020-04-15 8:51 ` J-P. Rosen @ 2020-04-17 14:20 ` Björn Lundin 2020-04-21 21:06 ` Randy Brukardt 1 sibling, 1 reply; 17+ messages in thread From: Björn Lundin @ 2020-04-17 14:20 UTC (permalink / raw) Den 2020-04-15 kl. 10:02, skrev AdaMagica: > Am Mittwoch, 15. April 2020 09:20:33 UTC+2 schrieb briot....@gmail.com: >> The approach I tend to use is using `System.Address_Image`: > > This is not in the RM. It must be GNAT specific, which you should have said. > Are you really saying that everything that is posted here must be checked with the RM? -- Björn ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Put the access value 2020-04-17 14:20 ` Björn Lundin @ 2020-04-21 21:06 ` Randy Brukardt 2020-04-22 12:31 ` Björn Lundin 0 siblings, 1 reply; 17+ messages in thread From: Randy Brukardt @ 2020-04-21 21:06 UTC (permalink / raw) [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain, Size: 866 bytes --] "Björn Lundin" <b.f.lundin@gmail.com> wrote in message news:r7cdvt$fp5$1@dont-email.me... > Den 2020-04-15 kl. 10:02, skrev AdaMagica: >> Am Mittwoch, 15. April 2020 09:20:33 UTC+2 schrieb briot....@gmail.com: >>> The approach I tend to use is using `System.Address_Image`: >> >> This is not in the RM. It must be GNAT specific, which you should have >> said. >> > > Are you really saying that everything that is posted here > must be checked with the RM? Ideally, everything posted here would note if it is GNAT-specific or something defined by Ada, because some of us do primarily use other Ada compilers. GNAT /= Ada! I realize that it isn't always easy to do, so I personally don't complain often, but it is definitely helpful to emphasize what is available to all Ada users and what is only available to a select group. Randy. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Put the access value 2020-04-21 21:06 ` Randy Brukardt @ 2020-04-22 12:31 ` Björn Lundin 2020-04-22 17:33 ` AdaMagica 0 siblings, 1 reply; 17+ messages in thread From: Björn Lundin @ 2020-04-22 12:31 UTC (permalink / raw) Den 2020-04-21 kl. 23:06, skrev Randy Brukardt: > "Björn Lundin" <b.f.lundin@gmail.com> wrote in message > news:r7cdvt$fp5$1@dont-email.me... >> Den 2020-04-15 kl. 10:02, skrev AdaMagica: >>> Am Mittwoch, 15. April 2020 09:20:33 UTC+2 schrieb briot....@gmail.com: >>>> The approach I tend to use is using `System.Address_Image`: >>> >>> This is not in the RM. It must be GNAT specific, which you should have >>> said. >>> >> >> Are you really saying that everything that is posted here >> must be checked with the RM? > > Ideally, everything posted here would note if it is GNAT-specific or > something defined by Ada, because some of us do primarily use other Ada > compilers. GNAT /= Ada! I do agree, but the tone of AdaMagica is more like a professor telling a student what to do or not. As if not helping the OP at all is much better than suggest something not portable, but might be a solution to the particular problem, where it is not stated if portability is a requirement or not. Irritating. -- Björn ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Put the access value 2020-04-22 12:31 ` Björn Lundin @ 2020-04-22 17:33 ` AdaMagica 2020-04-23 11:37 ` Björn Lundin 0 siblings, 1 reply; 17+ messages in thread From: AdaMagica @ 2020-04-22 17:33 UTC (permalink / raw) Am Mittwoch, 22. April 2020 14:31:11 UTC+2 schrieb björn lundin: > I do agree, but the tone of AdaMagica is more like a professor telling a > student what to do or not. I appoligize if my answer made this impression - this was not my intent. My thinking was: Someone not using GNAT might think "Oh, that's nice, I'll remember" and later "WTF? Isn't Ada always praised for its portability?" And there is that habit of many equalling GNAT and Ada (for instance claiming that body files must have the extension adb - even with GNAT, that isn't the case). ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Put the access value 2020-04-22 17:33 ` AdaMagica @ 2020-04-23 11:37 ` Björn Lundin 0 siblings, 0 replies; 17+ messages in thread From: Björn Lundin @ 2020-04-23 11:37 UTC (permalink / raw) Den 2020-04-22 kl. 19:33, skrev AdaMagica: > Am Mittwoch, 22. April 2020 14:31:11 UTC+2 schrieb björn lundin: >> I do agree, but the tone of AdaMagica is more like a professor telling a >> student what to do or not. > > I appoligize if my answer made this impression - this was not my intent. Through the written media it is sometimes hard to express intonations and it is sometimes hard to interpret the underlying tone of a message. I could have been more forgiving in my reply, and it is nice to know that the tone i read into it was not there. > My thinking was: Someone not using GNAT might think "Oh, that's nice, I'll remember" and later "WTF? Isn't Ada always praised for its portability?" Well that is true only so far. While i do agree with Randy that is is good to state the compiler, I don't think failure to do so should be rewarded with a 'you should have done that' And is it really enough to say it's gnat? I don't think the version of the language was mentioned (83/95/05/12/15/2x) (does both 15 and 12 exist?) I have had case where my collegues used 'Img (gnat-specifik) and then changed it to 'Image - part of a newer standard - for portability. Then that code has been moved to another project, where it fails to compile. That used gnat 7.4.2, which is 2012. but not 2015. And only the gnat specific attribute works there. And here I hear people say 'use type'image(varible) instead. But I do think Assignment_Id'image or Assignment_Id'Img is nicer than with Core_Types ... Core_Types.Assignment_Identity_Type'Image(Assignment_Id) which we did before to log out an Assignment_Id Another thing if working with operating system is the compiler's runtime tasking model. A piece of code using blocking calls for I/O in a thread will work well on implementations mapping tasks to os-threads, but will block the whole process if the tasking is made by the compiler runtime. Alysy Ada did that on AIX (Ada 83). And I think Janus as well. Object Ada (I think) and Gnat does not. There are likely other things that break portability So, should one state language version and runtime behaviour too? > And there is that habit of many equalling GNAT and Ada (for instance claiming that body files must have the extension adb - even with GNAT, that isn't the case). Yes, and that is unfortunate. But critisizing other helpful posts does not change that. If the OP would have tried the gnat-specific advice given, and failed, he/she would likely have come back and said 'no good' -- Björn ^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2020-04-23 11:37 UTC | newest] Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-04-14 7:15 Put the access value ldries46 2020-04-14 7:42 ` J-P. Rosen 2020-04-18 15:08 ` Oliver Kellogg 2020-04-20 23:02 ` Robert A Duff 2020-04-21 7:07 ` briot.emmanuel 2020-04-21 22:29 ` Robert A Duff 2020-04-14 11:05 ` Jeffrey R. Carter 2020-04-14 12:09 ` ldries46 2020-04-15 7:20 ` briot.emmanuel 2020-04-15 8:02 ` AdaMagica 2020-04-15 8:51 ` J-P. Rosen 2020-04-15 16:23 ` AdaMagica 2020-04-17 14:20 ` Björn Lundin 2020-04-21 21:06 ` Randy Brukardt 2020-04-22 12:31 ` Björn Lundin 2020-04-22 17:33 ` AdaMagica 2020-04-23 11:37 ` Björn Lundin
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox