× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On 2011/2/1 12:08 PM, Aaron Albertson wrote:

... here's something similar you can
do in RPG (formatting is off, but you get the idea):

D container_t ds qualified template
D i 10i 0
D j 10i 0
D container ds likeds(container_t)
D offsets ds likeds(container_t)
D pNode s *
D pContainer s *
/free
pNode = %addr(container.j);
pContainer = pNode - (%addr(offsets.j) - %addr(offsets));


Earlier today, I hadn't looked carefully enough for the README that Mihael pointed to. I was puzzled over how such a macro would be used, since the names of the structure and the structure member would have to be known at compile time.

Here's the sample function from the README:
int my_cmp(const struct avltree_node *a,
const struct avltree_node *b)
{
struct my_struct *p = avltree_container_of(a, my_struct, node);
struct my_struct *q = avltree_container_of(b, my_struct, node);

return p->key - q->key;
}

Here's an equivalent function in RPG (unformatted and untested). I marked the extra code needed to handle the C macro with ***, and the code that replaces the macro with "mac".

P my_cmp b
D my_cmp pi
D a * value
D b * value

D p ds likeds(my_struct_t)
D based(p_ptr)
D q ds likeds(my_struct_t)
D based(q_ptr)

*** D offsets ds likeds(my_struct_t)
*** D nodeOffset s 10i 0
/free
*** nodeOffset = %addr(offsets.node) - %addr(offsets);
mac p_ptr = a - nodeOffset;
mac q_ptr = b - nodeOffset;

return p.key - q.key;
/end-free
P e

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2023 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.