why does symbol & in #define QO_PTR(q_node, q_type, q_ptr) needed?

Discussion in 'C Programming' started by ooze, Jun 8, 2004.

  1. ooze

    ooze Guest

    typedef unsigned long PARAM;

    typedef PARAM SAP;

    typedef struct qnode
    {
    struct qnode *next;
    struct qnode *prev;
    }
    QNODE;

    typedef struct qhead
    {
    struct qnode *head;
    struct qnode *tail;
    }
    QHEAD;

    typedef struct
    {
    QHEAD qhead;
    int (*srv_req) (SAP sys_sap);
    SAP sys_sap;
    }
    SSRV_S;



    typedef struct sig_s
    {
    struct sig_s *next;
    struct sig_s *prev;
    int waiting;
    SAP ssrv_sap;
    SIG_FUNC func;
    SAP user_sap;
    PARAM ident;
    }
    SIG_S;
    /************************************************************************
    * slib_init
    *************************************************************************
    *
    */
    PUBLIC int slib_init
    (
    int (*func) (SAP SysSap),
    SAP sys_sap,
    SAP *ssrv_sap
    )
    {
    SSRV_S *ssrv;

    /* Self initialize, if needed.
    */
    if (! s_initialized)
    s_init ();

    /* Try to allocate a sap
    */
    #if MAX_SIG_SRV
    for (ssrv = ssrv_pool; ssrv < ssrv_pool + MAX_SIG_SRV; ++ssrv)
    if (ssrv->srv_req == NULL)
    break;
    if (ssrv >= ssrv_pool + MAX_SIG_SRV)
    return -1;
    #else
    ssrv = (SSRV_S *) MEM_ALLOC (sizeof (SSRV_S));
    if (ssrv == NULL)
    return -1;
    #endif

    /* Initialize it.
    */
    Q_INIT (&ssrv->qhead);
    ssrv->srv_req = func;
    ssrv->sys_sap = sys_sap;

    /* Tell the caller the address of the SSRV_S and return success.
    */
    *ssrv_sap = (SAP) ssrv;
    return 0;
    }


    /************************************************************************
    * slib_serv
    *************************************************************************
    *
    */
    PUBLIC void slib_serv
    (
    SAP ssrv_sap
    )
    {
    SSRV_S *ssrv = (SSRV_S *) ssrv_sap;
    SIG_S *sig;
    IPL_VALUE level;
    int limit = SIG_SERV_LIMIT;

    /* Call the functions for each signaled event.
    */
    while (((sig = (SIG_S *) ssrv->qhead.head) != NULL) && (limit-- > 0))
    {
    level = IPL_SET_NORMAL ();
    QO_REMOVE (sig, &ssrv->qhead, SIG_S, next);
    sig->waiting = 0;
    IPL_RESTORE (level);
    (*sig->func) (sig->user_sap, sig->ident);
    }
    }




    #define QO_REMOVE(q_node, q_head, q_type, q_ptr) { \
    register QNODE * node = (QNODE *) (void *) q_node; \
    register QHEAD * head = (QHEAD *) (void *) q_head; \
    if (QO_PTR(node, q_type, q_ptr)->prev == NULL) \
    head->head = QO_PTR(node, q_type, q_ptr)->next; \
    else \
    QO_PTR(QO_PTR(node, q_type, q_ptr)->prev, q_type, q_ptr)->next = \
    QO_PTR(node, q_type, q_ptr)->next; \
    if (QO_PTR(node, q_type, q_ptr)->next == NULL) \
    head->tail = QO_PTR(node, q_type, q_ptr)->prev; \
    else \
    QO_PTR(QO_PTR(node, q_type, q_ptr)->next, q_type, q_ptr)->prev = \
    QO_PTR(node, q_type, q_ptr)->prev; \
    QO_PTR(node, q_type, q_ptr)->next = NULL; \
    QO_PTR(node, q_type, q_ptr)->prev = NULL; \
    }



    #define QO_PTR(q_node, q_type, q_ptr) \
    ((QNODE *) (void *) (&((q_type *) (void *) q_node)->q_ptr))
     
    ooze, Jun 8, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ooze
    Replies:
    2
    Views:
    443
    Arthur J. O'Dwyer
    Jun 8, 2004
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    985
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,236
    Smokey Grindel
    Dec 2, 2006
  4. baumann@pan
    Replies:
    1
    Views:
    769
    Richard Bos
    Apr 15, 2005
  5. Song Ma
    Replies:
    2
    Views:
    260
    Charles Oliver Nutter
    Jul 20, 2008
Loading...

Share This Page