Thanx to all for the help. I got an example running now. Works well. But I think I'll write some wrapper service program to make it a little easier to use this lib.
Mihael
-----Original Message-----
From: c400-l-bounces+mihael.schmidt=rossmann.de@xxxxxxxxxxxx [mailto:c400-l-bounces+mihael.schmidt=rossmann.de@xxxxxxxxxxxx] On Behalf Of Barbara Morris
Sent: Wednesday, February 02, 2011 12:23 AM
To: c400-l@xxxxxxxxxxxx
Subject: Re: [C400-L] inline function
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.