Thread: Structure - Typedef accessing problem

  1. #1
    eat my shorts!
    Join Date
    Apr 2002
    Posts
    294

    Arrow Structure - Typedef accessing problem

    Hi,

    Code:
    typedef enum RelationalOperators  {EQ, NE, GT, LT} Rel_Op;
    Code:
    typedef union TokenAttribute{
    	Rel_Op rel_op;  
      } TA;
    Code:
    typedef struct Token
    {
    	TA attribute;
    } Token;
    Code:
    token temp;
    
    temp.attribute.rel_op[0];          /*error*/
    i am trying to access the EQ, NE, GT, and LT to do certain operations afterwards - but cant seem to get the syntax right...
    Games Reviews Previews Desktop Themes Downloads Paintball Forums Shareware Freeware and much more

    The best in Technology and Gaming News

    www.back2games.com

  2. #2
    eat my shorts!
    Join Date
    Apr 2002
    Posts
    294

    Arrow Structure - Typedef accessing problem

    <<threads merged>>

    Code:
    typedef enum RelationalOperators  {EQ, NE, GT, LT} Rel_Op;
    
    
    typedef union TokenAttribute{
    	Rel_Op rel_op;  
      } TA;
    
    typedef struct Token
    {
    	TA attribute; /* token attribute */
    } Token;

    Code:
    Token temp;
    temp.attribute.rel_op[0];       /*error*/
    I have been trying ti access the rel_op as i need to compare the content...but cant seem to get the syntax right...
    Games Reviews Previews Desktop Themes Downloads Paintball Forums Shareware Freeware and much more

    The best in Technology and Gaming News

    www.back2games.com

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Code:
     if (temp.attribute.rel_op == EQ)
    will test if the enum contains a particular value. The left hand side of the comparison accesses the value in your variable.

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    rel_op isn't an array, and you're trying to use it like one. Maybe you should just use an array instead of an enum?

    Honestly it's a little hard to give advice, since I can't tell what you're really trying to do.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > typedef union TokenAttribute
    Is there something you're not telling us, because a union with only one member is a struct.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 06-04-2009, 02:03 PM
  2. Problem with custom structure
    By stickman in forum C++ Programming
    Replies: 9
    Last Post: 10-14-2006, 02:57 PM
  3. Structure and typedef
    By Roaring_Tiger in forum C Programming
    Replies: 6
    Last Post: 03-12-2003, 08:27 PM
  4. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM
  5. Pointer to structure problem
    By unregistered in forum C Programming
    Replies: 3
    Last Post: 12-24-2001, 07:54 AM