Prev: pack problem with intel 11.1
Next: solutions book
From: GianLuigi Piacentini on 23 Jul 2010 13:34 Dear Fortraneers, I would like to test 2 pointers for pointing to the same object: specifically 2 pointers to list elements like TYPE element INTEGER :: payload TYPE(element), POINTER :: next END TYPE element elements are allocated and linked together, and I only know some current elements along the list, say cursor_1 and cursor_2, defined as TYPE cursor TYPE(element), POINTER :: current END TYPE cursor Now I would like to test 2 cursors for pointing to the same element, say cursor_1%current%next == cursor_2%current%next since payloads may be the same. In C I would compare the addresses, but Fortran automatically dereferences pointers and the expression becomes a comparison between 2 derived types, and the compiler (G95 0.92) complains. Whad do you suggest to solve this ? Thanks in advance. G.L. Piacentini
From: Richard Maine on 23 Jul 2010 13:48 GianLuigi Piacentini <ggpiace(a)tin.it> wrote: > I would like to test 2 pointers for pointing to the same object: See the 2-argument form of the ASSOCIATED intrinsic. That's exactly what it does. (Well, almost exactly. If you have zero-sized array targets, it behaves in a way I consider counter-intuitive. But as long as your targets don't have zero size, it gives the "obvious" answer.) -- Richard Maine | Good judgment comes from experience; email: last name at domain . net | experience comes from bad judgment. domain: summertriangle | -- Mark Twain
From: robin on 23 Jul 2010 21:08 "GianLuigi Piacentini" <ggpiace(a)tin.it> wrote in message news:4c49d299$0$40287$4fafbaef(a)reader2.news.tin.it... | Dear Fortraneers, | | I would like to test 2 pointers for pointing to the same object: | specifically 2 pointers to list elements like | TYPE element | INTEGER :: payload | TYPE(element), POINTER :: next | END TYPE element | elements are allocated and linked together, and I only know some | current | elements along the list, say cursor_1 and cursor_2, defined as | TYPE cursor | TYPE(element), POINTER :: current | END TYPE cursor | Now I would like to test 2 cursors for pointing to the same element, | say | cursor_1%current%next == cursor_2%current%next Use the ASSOCIATED builtin for testing whether two pointers are looking at the same thing. You can also use it for checkikng whether a pointer is pointing at anything.
|
Pages: 1 Prev: pack problem with intel 11.1 Next: solutions book |