C - Macro problem with nested structures

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Cagin
    New Member
    • Jun 2011
    • 2

    C - Macro problem with nested structures

    I define a macro like this:

    Code:
    #define L(p) ((p).value.len)
    
    typedef struct node
    {
    	int dimension;
    	int position;
    	int size;
    
    	union 
    	{
    	    long len;
    	    float f;
    
    	    } value;
    
    	struct node *prev;
    	struct node *next;
    
    } node, *np;
    and later,when I try to use that macro,
    I have this error:
    "error:requ est for member 'value' in something not a structure or union "

    So can you please help me to fix this problem?
    Is there any other way to define macros for nested structs?
    Last edited by Banfa; Jun 16 '11, 11:06 AM. Reason: Removed the extra blank lines
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    We need to see the code that uses the macro as in addition to what you have already posted.

    But my guess is that you have passed a pointer to your macro which is expecting a structure.

    Comment

    • Cagin
      New Member
      • Jun 2011
      • 2

      #3
      Yeah, you are right. I used to have a pointer problem, I fixed it. Thanks for help.

      Comment

      Working...