Thread: List_head

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    269

    List_head

    I'm new to C. In this project I'm working on, there's this line of code in bold.

    Code:
    typedef struct dimensions_
    {
        char *name;
          LIST_HEAD(alts, altname_) altlist;
          LIST_ENTRY(dimensions_) entries;
    } dimensions;
    altname_ is a struct defined above, but there is no alts defined anywhere.

    I've checked all of the associated header files, but I can't seem to find alts... what is this? How is this used?

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    269
    Am I just an idiot?

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    583
    man page LIST_HEAD section 3

    A list is headed by a structure defined by the LIST_HEAD macro. This
    structure contains a single pointer to the first element on the list.
    The elements are doubly linked so that an arbitrary element can be
    removed without traversing the list. New elements can be added to the
    list after an existing element, before an existing element, or at the
    head of the list. A LIST_HEAD structure is declared as follows:

    LIST_HEAD(HEADNAME, TYPE) head;
    So alts isn't defined before this because it is defined using this macro.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    269
    Quote Originally Posted by smokeyangel View Post
    man page LIST_HEAD section 3



    So alts isn't defined before this because it is defined using this macro.
    I see.. so I could pass in anything then, even xyzalts and it would work exactly the same?
    Last edited by dayalsoap; 09-17-2010 at 05:55 PM.

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    583
    Yup - any legal variable name.

    It's a macro -- it'll expand to something like

    struct xyzalts = Some init value;

    If it helps to know what it's expanded to, I think gcc -E will run the output through the preprocessor and output the result. Sometimes it's the easiest way to untangle complex poorly documented macros.

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    269
    Quote Originally Posted by smokeyangel View Post
    Yup - any legal variable name.

    It's a macro -- it'll expand to something like

    struct xyzalts = Some init value;

    If it helps to know what it's expanded to, I think gcc -E will run the output through the preprocessor and output the result. Sometimes it's the easiest way to untangle complex poorly documented macros.
    thank you very much for your help. that explains everything.

Popular pages Recent additions subscribe to a feed