Structure / Union Error

This is a discussion on Structure / Union Error within the C Programming forums, part of the General Programming Boards category; Code: cli_reliable.c: In function `rel_receive_packet': cli_reliable.c:46: error: request for member `header' in something not a structure or union When compiling ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    22

    Structure / Union Error

    Code:
    cli_reliable.c: In function `rel_receive_packet':
    cli_reliable.c:46: error: request for member `header' in something not a structure or union
    When compiling with the latest gcc. Here is the relative code:

    Code:
    #define PACKET_SIZE 64
    #define HEADER_SIZE sizeof(HEADER)
    #define MAX_DATA PACKET_SIZE-HEADER_SIZE
    
    typedef struct
    {
        char is_data;   // 1 if this is a data packet, 0 for an ack
        int fragment;   // fragment number (zero indexed)
        char last;      // 1 if this is the last packet in the message, 0 otherwise
        int datalen;    // length of data in bytes - only used for last packet
    } HEADER;
    
    typedef struct
    {
        HEADER header;  // the packet header (described above)
        char data[MAX_DATA];    // the contents of the packet
    } PACKET;
    
    
    int rel_receive_packet(int socket, PACKET *packet, int required_frag, int verbose, int reliable)
    {
        //if reliable transmission is turned off, just get the next packet
        int result = socket_receive_packet(socket, packet, reliable);
        
        if ( packet.header.fragment != required_frag )
        {
      
    ........................
            
        return result;
            
    }
    Am I missing something?
    Last edited by JimpsEd; 11-11-2006 at 01:03 PM.

  2. #2
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    Code:
    packet.header.fragment
    packet is a struct pointer. To derefernce the data elements use '->' operator
    so code looks something like this now

    Code:
    packet->header.fragment
    
    or
    
    (*packet).header.fragment // not a good idea
    ssharish2005
    Last edited by ssharish2005; 11-11-2006 at 01:07 PM.

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    22
    Solved.

    packet is a pointer, so to access a member I need to use ->

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 01:17 AM
  3. Getting other processes class names
    By Hawkin in forum Windows Programming
    Replies: 3
    Last Post: 03-20-2008, 05:02 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21