Thread: How do we typedef a forwards declaration ?

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    53

    How do we typedef a forwards declaration ?

    Hello,

    Please view the simple code below. I am trying to forwards declare pc. But I would like to typedef the forwards declaration so I don't have to repeat the "struct" key word every time I want to pass a pointer of pc type.

    Thanks in advance.


    Code:
    ========main.c (does nothing)
    #include <stdio.h>
    #include "PC.h"
    #include "REC.h"
     
    int main()
    {...}
    
    ===========PC.h
    #ifndef PC_H
    #define PC_H
    
    #include "REC.h"
    typedef struct tag_pc {                               			
    unsigned short  gso_flash_address;              
    } pc;                                                 		
    
    #endif // PC_H //
    
    ==========PC.c
    #include <stdio.h>
    #include "PC.h"
    // Methods here...
    
    ==========REC.h
    #ifndef REC_H
    #define REC_H
    
    //struct tag_pc;  	// Forwards declaration using the struct key word
    typedef struct tag_pc pc;  // <<< ?????? How to forward declare using typedef
    
    typedef struct tag_rec_data{
    unsigned short LKdct__F1;          
    }rec_data;
    
    typedef struct tag_rec {
    unsigned short f__pc_xchoice; 				     
    rec_data *records;
    }rec;                           
    
    int REC_match_link_id(pc  *pObj);        //<< error here   
    
    #endif // REC_H //
    
    =============REC.c
    #include <plib.h>
    #include "PC.h"
    #include "REC.h"
    
    int REC_match_link_id(pc     *pObj)  {...}         // <<<<error here!
    Last edited by see the big C; 12-05-2010 at 03:34 PM.

  2. #2
    Registered User
    Join Date
    Jun 2010
    Posts
    53
    Nevermind I see it. Obviously I am redeclaring pc !!!
    So renaming this:
    Code:
    typedef struct tag_pc pc;
    int REC_match_link_id(pc     *pObj)  {...}       
    
    to this:
    typedef struct tag_pc pcc;
    int REC_match_link_id(pcc     *pObj)  {...}
    fixed it.
    Rob

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, 08:18 PM
  2. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 12:36 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM