* for x'address or variant @ 2003-04-20 11:50 kat-Zygfryd 2003-04-20 14:05 ` James S. Rogers ` (2 more replies) 0 siblings, 3 replies; 18+ messages in thread From: kat-Zygfryd @ 2003-04-20 11:50 UTC (permalink / raw) I have a tiny problem, I want to have a structure: type P is access X; type X is record next: array(1..2) of P; left: P; right: P; end record; wherein the left component uses next(1)'address and right component uses next(2)'address, unfortunately "for x'address use" statements are not allowed within record declarations, and variant records don't allow me to access both next and left/right exchangably. do you know a way to work this out? Zygfryd @gnat3.15 ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: for x'address or variant 2003-04-20 11:50 for x'address or variant kat-Zygfryd @ 2003-04-20 14:05 ` James S. Rogers 2003-04-20 15:17 ` Steve 2003-04-20 16:19 ` Nick Roberts 2 siblings, 0 replies; 18+ messages in thread From: James S. Rogers @ 2003-04-20 14:05 UTC (permalink / raw) "kat-Zygfryd" <6667@wp.pl> wrote in message news:b7u1jh$p6k$1@news.onet.pl... > I have a tiny problem, I want to have a structure: > type P is access X; > type X is record > next: array(1..2) of P; > left: P; > right: P; > end record; > wherein the left component uses next(1)'address > and right component uses next(2)'address, > unfortunately "for x'address use" statements are > not allowed within record declarations, and > variant records don't allow me to access both > next and left/right exchangably. do you know a way > to work this out? You want a record that holds two values. The problem is that you want each value aliased by two fields. My first question is "why". If next(1) will always be the same as left, and next(2) will always be the same as right, then what do you gain by having two names for the same value in a single record? What are you trying to achieve? I do not see how your intended design is any better than type P is access X; type X is record left : P; right : P; end record; Of course, this simple design also reveals that X is a node of a doubly linked list of nothing. In other words, the node contains no data except its position in a list. Such a data structure is generally useless. Jim Rogers ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: for x'address or variant 2003-04-20 11:50 for x'address or variant kat-Zygfryd 2003-04-20 14:05 ` James S. Rogers @ 2003-04-20 15:17 ` Steve 2003-04-20 16:19 ` Nick Roberts 2 siblings, 0 replies; 18+ messages in thread From: Steve @ 2003-04-20 15:17 UTC (permalink / raw) First: If you're a newbie to Ada, you're taking the wrong approach. If that is the case, please elaborate a little more on the problem you're trying to solve, maybe we can help with a different approach. Second: If you're not a newbie and are showing a small subset of the problem without the gory details, there is a pragma defined for the intent of interfacing with C called "Unchecked_Union" that would allow you to do this. The pragma is not currently (as far as I know) supported by the standard, but is available with Gnat and ObjectAda (maybe more). The Win32Ada bindings have an example of the use of this pragma. Steve (The Duck) "kat-Zygfryd" <6667@wp.pl> wrote in message news:b7u1jh$p6k$1@news.onet.pl... > I have a tiny problem, I want to have a structure: > type P is access X; > type X is record > next: array(1..2) of P; > left: P; > right: P; > end record; > wherein the left component uses next(1)'address > and right component uses next(2)'address, > unfortunately "for x'address use" statements are > not allowed within record declarations, and > variant records don't allow me to access both > next and left/right exchangably. do you know a way > to work this out? > > Zygfryd @gnat3.15 > > ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: for x'address or variant 2003-04-20 11:50 for x'address or variant kat-Zygfryd 2003-04-20 14:05 ` James S. Rogers 2003-04-20 15:17 ` Steve @ 2003-04-20 16:19 ` Nick Roberts 2003-04-20 16:57 ` kat-Zygfryd 2 siblings, 1 reply; 18+ messages in thread From: Nick Roberts @ 2003-04-20 16:19 UTC (permalink / raw) "kat-Zygfryd" <6667@wp.pl> wrote in message news:b7u1jh$p6k$1@news.onet.pl... > I have a tiny problem, I want to have a structure: > type P is access X; > type X is record > next: array(1..2) of P; > left: P; > right: P; > end record; > wherein the left component uses next(1)'address > and right component uses next(2)'address, > unfortunately "for x'address use" statements are > not allowed within record declarations, and > variant records don't allow me to access both > next and left/right exchangably. do you know a way > to work this out? Declare the following: type Node; type Node_Ref is access Node; type Leaf_Direction is (Left, Right); type Leaf_Pair is array (Leaf_Direction) of Node_Ref; type Node is record Payload: ...; Leaves: Leaf_Pair; end record; Now you can reference, for example, the left leaf an object X1 of type Node by: X1.Leaves(Left).all You can cycle through all the leaves of X1 by: for L in Leaf_Direction loop ... X1.Leaves(L).all ... end loop; I hope this solves the problem. Say if it doesn't. -- Nick Roberts Jabber: debater@charente.de [ICQ: 159718630] ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: for x'address or variant 2003-04-20 16:19 ` Nick Roberts @ 2003-04-20 16:57 ` kat-Zygfryd 2003-04-20 16:17 ` Simon Wright 0 siblings, 1 reply; 18+ messages in thread From: kat-Zygfryd @ 2003-04-20 16:57 UTC (permalink / raw) "Nick Roberts" <nickroberts@blueyonder.co.uk> wrote in message news:b7uhb9$4lb72$1@ID-25716.news.dfncis.de... > Declare the following: > > type Node; > type Node_Ref is access Node; > type Leaf_Direction is (Left, Right); > type Leaf_Pair is array (Leaf_Direction) of Node_Ref; > type Node is > record > Payload: ...; > Leaves: Leaf_Pair; > end record; > > Now you can reference, for example, the left leaf an object X1 of type Node > by: > > X1.Leaves(Left).all > > You can cycle through all the leaves of X1 by: > > for L in Leaf_Direction loop > ... X1.Leaves(L).all ... > end loop; > > I hope this solves the problem. Say if it doesn't. > > -- > Nick Roberts > Jabber: debater@charente.de [ICQ: 159718630] of course it does, but I wanted it to be done a little more good-looking, thanks anyway. Zygfryd ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: for x'address or variant 2003-04-20 16:57 ` kat-Zygfryd @ 2003-04-20 16:17 ` Simon Wright 2003-04-20 18:07 ` kat-Zygfryd 0 siblings, 1 reply; 18+ messages in thread From: Simon Wright @ 2003-04-20 16:17 UTC (permalink / raw) "kat-Zygfryd" <6667@wp.pl> writes: > "Nick Roberts" <nickroberts@blueyonder.co.uk> wrote in message > news:b7uhb9$4lb72$1@ID-25716.news.dfncis.de... > > I hope this solves the problem. Say if it doesn't. > of course it does, but I wanted it to be done > a little more good-looking, thanks anyway. Nick's solution looks pretty good to me, in general anything which uses arrays indexed by (1..2) rather than some problem-specific index like Nick's, or which relies on 'Address, is at best suspect! ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: for x'address or variant 2003-04-20 16:17 ` Simon Wright @ 2003-04-20 18:07 ` kat-Zygfryd 2003-04-20 19:39 ` Robert A Duff 0 siblings, 1 reply; 18+ messages in thread From: kat-Zygfryd @ 2003-04-20 18:07 UTC (permalink / raw) "Simon Wright" <simon@pushface.org> wrote in message news:x7v1xzxjg86.fsf@smaug.pushface.org... > "kat-Zygfryd" <6667@wp.pl> writes: > Nick's solution looks pretty good to me, in general anything which > uses arrays indexed by (1..2) rather than some problem-specific index > like Nick's, or which relies on 'Address, is at best suspect! If you say so, I just thought that using a component would be at least an instruction or two faster than indexing an array [but I need the array solution also in some places]. Anyway it could be useful to enable use of unrestricted variants in Ada 2005, I guess just that programmers using the feature would need to know what they are doing. (Which is quite certain since Ada programmers are very careful, geneticly ;P ) example: record case not_needed_selector is when sth => B32: Integer; when sth => B8_1,B8_2,B8_3,B8_4:Byte; when sth => array(1..4) of Byte; end case; end record; or something alike, no more explicit typecasts needed in such case Zygfryd ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: for x'address or variant 2003-04-20 18:07 ` kat-Zygfryd @ 2003-04-20 19:39 ` Robert A Duff 2003-04-20 21:17 ` kat-Zygfryd 0 siblings, 1 reply; 18+ messages in thread From: Robert A Duff @ 2003-04-20 19:39 UTC (permalink / raw) "kat-Zygfryd" <6667@wp.pl> writes: > If you say so, I just thought that using a component > would be at least an instruction or two faster than > indexing an array ... Than indexing an array by a static index value? I doubt it. Seems like you ought to prove (by measuring, and reading the assembly code) that this is a real problem before you start playing low-level games like this for efficiency reasons. - Bob ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: for x'address or variant 2003-04-20 19:39 ` Robert A Duff @ 2003-04-20 21:17 ` kat-Zygfryd 2003-04-21 2:25 ` John R. Strohm 0 siblings, 1 reply; 18+ messages in thread From: kat-Zygfryd @ 2003-04-20 21:17 UTC (permalink / raw) "Robert A Duff" <bobduff@shell01.TheWorld.com> wrote in message news:wccadel9cw7.fsf@shell01.TheWorld.com... > Seems like you ought to prove (by measuring, and reading the assembly > code) that this is a real problem before you start playing low-level > games like this for efficiency reasons. > > - Bob Perhaps you are right, I just wanted to make my most commonly used algorithms 100% as efficient as I can. I don't really know what does the compiler optimize and what does it not. Zygfryd ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: for x'address or variant 2003-04-20 21:17 ` kat-Zygfryd @ 2003-04-21 2:25 ` John R. Strohm 2003-04-21 10:26 ` kat-Zygfryd 0 siblings, 1 reply; 18+ messages in thread From: John R. Strohm @ 2003-04-21 2:25 UTC (permalink / raw) "kat-Zygfryd" <6667@wp.pl> wrote in message news:b7v2qr$bto$1@news.onet.pl... > "Robert A Duff" <bobduff@shell01.TheWorld.com> wrote in message > news:wccadel9cw7.fsf@shell01.TheWorld.com... > > Seems like you ought to prove (by measuring, and reading the assembly > > code) that this is a real problem before you start playing low-level > > games like this for efficiency reasons. > > > > - Bob > > Perhaps you are right, I just wanted to make my > most commonly used algorithms 100% as efficient > as I can. I don't really know what does the compiler > optimize and what does it not. Dude, the rule is FIRST you make your code CORRECT, absolutely positively CORRECT, and *THEN* you worry about making it fast. ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: for x'address or variant 2003-04-21 2:25 ` John R. Strohm @ 2003-04-21 10:26 ` kat-Zygfryd 2003-04-21 12:59 ` Robert A Duff 0 siblings, 1 reply; 18+ messages in thread From: kat-Zygfryd @ 2003-04-21 10:26 UTC (permalink / raw) "John R. Strohm" <strohm@airmail.net> wrote in message news:52C30E21B2695ADA.9A5568A9039EC23D.34356CD468622AAC@lp.airnews.net... > Dude, the rule is FIRST you make your code CORRECT, absolutely positively > CORRECT, and *THEN* you worry about making it fast. I'm rewriting the code from a C version from a book, DUDE. Zygfryd ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: for x'address or variant 2003-04-21 10:26 ` kat-Zygfryd @ 2003-04-21 12:59 ` Robert A Duff 2003-04-21 16:29 ` kat-Zygfryd 0 siblings, 1 reply; 18+ messages in thread From: Robert A Duff @ 2003-04-21 12:59 UTC (permalink / raw) "kat-Zygfryd" <6667@wp.pl> writes: > I'm rewriting the code from a C version from a book, Please show us what the C code looks like. > DUDE. > > Zygfryd - Bob ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: for x'address or variant 2003-04-21 12:59 ` Robert A Duff @ 2003-04-21 16:29 ` kat-Zygfryd 2003-04-21 17:25 ` tmoran 2003-04-21 19:48 ` Robert A Duff 0 siblings, 2 replies; 18+ messages in thread From: kat-Zygfryd @ 2003-04-21 16:29 UTC (permalink / raw) "Robert A Duff" <bobduff@shell01.TheWorld.com> wrote in message news:wccvfx82egs.fsf@shell01.TheWorld.com... > "kat-Zygfryd" <6667@wp.pl> writes: > > Please show us what the C code looks like. > - Bob It's LIBAVL 2.0.1 PDF doc, you can find it and download. However I didn't mean that those structures where used in this C code, just that it is correct code (I guess, version 2.0.1 after all). Zygfryd PS. I am deeply unsatisfied because I posted a question to aquire an answer, not for my coding style/skills to be discussed, as some people tend to do. ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: for x'address or variant 2003-04-21 16:29 ` kat-Zygfryd @ 2003-04-21 17:25 ` tmoran 2003-04-21 19:48 ` Robert A Duff 1 sibling, 0 replies; 18+ messages in thread From: tmoran @ 2003-04-21 17:25 UTC (permalink / raw) > I am deeply unsatisfied because I posted > a question to aquire an answer, not for my > coding style/skills to be discussed, as Why should we spend time answering what are clearly the wrong questions? ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: for x'address or variant 2003-04-21 16:29 ` kat-Zygfryd 2003-04-21 17:25 ` tmoran @ 2003-04-21 19:48 ` Robert A Duff 2003-04-21 20:12 ` kat-Zygfryd 1 sibling, 1 reply; 18+ messages in thread From: Robert A Duff @ 2003-04-21 19:48 UTC (permalink / raw) "kat-Zygfryd" <6667@wp.pl> writes: > "Robert A Duff" <bobduff@shell01.TheWorld.com> wrote in message > news:wccvfx82egs.fsf@shell01.TheWorld.com... > > "kat-Zygfryd" <6667@wp.pl> writes: > > > > Please show us what the C code looks like. > > - Bob > > It's LIBAVL 2.0.1 PDF doc, you can find it > and download. However I didn't mean that > those structures where used in this C code, > just that it is correct code (I guess, version > 2.0.1 after all). I was trying to help, but I need to understand what you're trying to do. I'm not willing to download and read all the LIBAVL code. I looked for it briefly, and it's too much hassle. I'm guessing you've got some C code, and you want to know how to do similar things in Ada. So post some simple examples in C. If that's what you're after, please explain. > Zygfryd > > PS. > I am deeply unsatisfied because I posted > a question to aquire an answer, not for my > coding style/skills to be discussed, as > some people tend to do. I'm not interested in discussing your *skills*. But you seem to be asking about Ada *style*, so... - Bob ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: for x'address or variant 2003-04-21 19:48 ` Robert A Duff @ 2003-04-21 20:12 ` kat-Zygfryd 2003-04-21 20:55 ` Robert A Duff 2003-04-22 12:02 ` John R. Strohm 0 siblings, 2 replies; 18+ messages in thread From: kat-Zygfryd @ 2003-04-21 20:12 UTC (permalink / raw) "Robert A Duff" <bobduff@shell01.TheWorld.com> wrote in message news:wccfzob6384.fsf@shell01.TheWorld.com... > I was trying to help, but I need to understand what you're trying to do. > I'm not willing to download and read all the LIBAVL code. > I looked for it briefly, and it's too much hassle. > > I'm guessing you've got some C code, and you want to know how to do > similar things in Ada. So post some simple examples in C. > If that's what you're after, please explain. Not really, I have code in C which is easily translatable to Ada, I just wanted to know how to perform the thing I was talking about (it isn't nessessary for this code, just a bit helpful) > I'm not interested in discussing your *skills*. > But you seem to be asking about Ada *style*, so... > > - Bob Oh I didn't mean you, but mr. Strohm. Zygfryd ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: for x'address or variant 2003-04-21 20:12 ` kat-Zygfryd @ 2003-04-21 20:55 ` Robert A Duff 2003-04-22 12:02 ` John R. Strohm 1 sibling, 0 replies; 18+ messages in thread From: Robert A Duff @ 2003-04-21 20:55 UTC (permalink / raw) "kat-Zygfryd" <6667@wp.pl> writes: > Not really, I have code in C which is easily translatable to Ada, OK, given *that* statement I would think you're done. But you say: > I just wanted to know how to perform the thing I was talking > about (it isn't nessessary for this code, just a bit helpful) The "thing you were talking about" was overlaying integer record fields with other fields that are arrays of integers. I have no idea why you want to do that (at first you said, speed, but it's probably not faster), so I'm really unsure what you're trying to accomplish, so I can't say how one would do it in Ada. - Bob ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: for x'address or variant 2003-04-21 20:12 ` kat-Zygfryd 2003-04-21 20:55 ` Robert A Duff @ 2003-04-22 12:02 ` John R. Strohm 1 sibling, 0 replies; 18+ messages in thread From: John R. Strohm @ 2003-04-22 12:02 UTC (permalink / raw) "kat-Zygfryd" <6667@wp.pl> wrote in message news:b81jc5$4u7$1@news.onet.pl... > "Robert A Duff" <bobduff@shell01.TheWorld.com> wrote in message > news:wccfzob6384.fsf@shell01.TheWorld.com... > > I was trying to help, but I need to understand what you're trying to do. > > I'm not willing to download and read all the LIBAVL code. > > I looked for it briefly, and it's too much hassle. > > > > I'm guessing you've got some C code, and you want to know how to do > > similar things in Ada. So post some simple examples in C. > > If that's what you're after, please explain. > > Not really, I have code in C which is easily translatable to Ada, > I just wanted to know how to perform the thing I was talking > about (it isn't nessessary for this code, just a bit helpful) > > > I'm not interested in discussing your *skills*. > > But you seem to be asking about Ada *style*, so... > > > > - Bob > > Oh I didn't mean you, but mr. Strohm. I stand by my statement. Until you have correct, RUNNING code, in your target language, it is premature to worry about "efficiency". You should give thought to choosing the appropriate algorithm, but trying to make micro-optimizations before the code is known to be correct and working is the wrong approach. Furthermore, many years of study have shown conclusively that human programmers are very poor at finding the real "hot spots" where optimization can really help. Profiling the actual execution time, mapping out where the program is actually spending the cycles, is absolutely critical. ^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2003-04-22 12:02 UTC | newest] Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2003-04-20 11:50 for x'address or variant kat-Zygfryd 2003-04-20 14:05 ` James S. Rogers 2003-04-20 15:17 ` Steve 2003-04-20 16:19 ` Nick Roberts 2003-04-20 16:57 ` kat-Zygfryd 2003-04-20 16:17 ` Simon Wright 2003-04-20 18:07 ` kat-Zygfryd 2003-04-20 19:39 ` Robert A Duff 2003-04-20 21:17 ` kat-Zygfryd 2003-04-21 2:25 ` John R. Strohm 2003-04-21 10:26 ` kat-Zygfryd 2003-04-21 12:59 ` Robert A Duff 2003-04-21 16:29 ` kat-Zygfryd 2003-04-21 17:25 ` tmoran 2003-04-21 19:48 ` Robert A Duff 2003-04-21 20:12 ` kat-Zygfryd 2003-04-21 20:55 ` Robert A Duff 2003-04-22 12:02 ` John R. Strohm
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox