Portierungsproblem mit einer Struktur



  • Ich habe folgenden Code in einer C-header Datei ich muss diese Headerdatei und den zugehörigen C-Code in einem cpp programm nutzen
    Allerdings bekomme ich folgende Fehlermeldung wenn ich es mit dem Visual C 6.0
    als cpp compiliere

    u:\library\incl\msgdecode.h(66) : error C2371: 'BASESTRUCT' : Neudefinition; unterschiedliche Basistypen
    u:\library\incl\msgdecode.h(60) : Siehe Deklaration von 'BASESTRUCT'

    Kann mir jemand helfen es zu portieren ohne es neu als C++ zu kodieren.

    //----------------------------------
    typedef struct
    {
      int use;	 // this entry is commanded to be decoded
      int Type;	 // type of data record [RE, RI, EN, FP]
      char name[NORMSTRINGLEN];  //Nametext
      struct BASESTRUCT *next;   // Pointer to next item in list the last item is set to NULL
      struct BASESTRUCT *prev;   // Pointer to previous item in list the first itme is set to NULL
      void *TypData;	     // Pointer auf die Typspezifischen Daten, NULL default will be filled with typ specific data
      int Start;		     // Start Bit, first bit to decode in word for this item
      int Number;		     // AnzahlBits number of bits to decode for this item
    }
    BASESTRUCT;					 // structure common to all items, containing pointers to next an previous item in that list
    


  • Hast Du im Header includewächter ?



  • Lass das typedef weg.



  • oder so:

    typedef struct BASESTRUCTtag
    { 
      int use;     // this entry is commanded to be decoded 
      int Type;     // type of data record [RE, RI, EN, FP] 
      char name[5];  //Nametext 
      struct BASESTRUCTtag *next;   // Pointer to next item in list the last item is set to NULL 
      struct BASESTRUCTtag *prev;   // Pointer to previous item in list the first itme is set to NULL 
      void *TypData;         // Pointer auf die Typspezifischen Daten, NULL default will be filled with typ specific data 
      int Start;             // Start Bit, first bit to decode in word for this item 
      int Number;             // AnzahlBits number of bits to decode for this item 
    } 
    BASESTRUCT;                     // structure common to all items, containing pointers to next an previous item in that list
    


  • @Mibo Danke, der Vorschlag funktioniert



  • PAD schrieb:

    @Mibo Danke, der Vorschlag funktioniert

    das ist aber C und haesslich

    schreib einfach:

    struct BASESTRUCT
    {  
      int use;     // this entry is commanded to be decoded  
      int Type;     // type of data record [RE, RI, EN, FP]  
      char name[5];  //Nametext  
      struct BASESTRUCT *next;   // Pointer to next item in list the last item is set to NULL  
      struct BASESTRUCT *prev;   // Pointer to previous item in list the first itme is set to NULL  
      void *TypData;         // Pointer auf die Typspezifischen Daten, NULL default will be filled with typ specific data  
      int Start;             // Start Bit, first bit to decode in word for this item  
      int Number;             // AnzahlBits number of bits to decode for this item  
    };
    


  • @Shade
    wenn der Code zu einem C Programm gehört, was er in einem C++ Programm benutzen will, dann kommt er wohl nicht drum rum dort C Code zu verwenden.

    btw. könnte man in C++ ja auch das struct weglassen, wenn man den Typ benutzt



  • kingruedi schrieb:

    @Shade
    wenn der Code zu einem C Programm gehört, was er in einem C++ Programm benutzen will, dann kommt er wohl nicht drum rum dort C Code zu verwenden.

    warum muss er den C code dann aendern?

    ich habe es so verstanden, dass der C code jetzt als c++ code kompiliert wird.



  • warum muss er den C code dann aendern?

    weil der Code auch als C Code falsch ist

    ich habe es so verstanden, dass der C code jetzt als c++ code kompiliert wird.

    dann kann man das natürlich ändern

    (btw. wenn ich recht hab, gehört das eh nach ANSI C)



  • kingruedi schrieb:

    weil der Code auch als C Code falsch ist

    oh, so genau hab ich nicht hingesehen...
    aber stimmt.

    jetzt verstehe ich garnix mehr.



  • Shade Of Mine schrieb:

    kingruedi schrieb:

    weil der Code auch als C Code falsch ist

    jetzt verstehe ich garnix mehr.

    Was ist an dem C Konstruct mit typedef struct falsch?

    BTW ich weis das das für diese Frage das falsche Forum ist, aber bitte trotzdem eine Antwort



  • PAD schrieb:

    Was ist an dem C Konstruct mit typedef struct falsch?

    struct BASESTRUCT *next
    kann er nicht kennen, denn durch das typedef wird erst 'ausgewertet' wenn die struct vollstaendig definiert ist.

    Mibos Loesung ist die C Loesung
    und meine die C++ Loesung.



  • Shade Of Mine schrieb:

    und meine die C++ Loesung.

    nicht ganz

    das wär die C++ Lösung (wobei man in C++ das wahrscheinlich vom Konzept her ganz anders machen würde :))

    struct BASESTRUCT 
    {   
      int use;     // this entry is commanded to be decoded   
      int Type;     // type of data record [RE, RI, EN, FP]   
      char name[5];  //Nametext   
      BASESTRUCT *next;   // Pointer to next item in list the last item is set to NULL   
      BASESTRUCT *prev;   // Pointer to previous item in list the first itme is set to NULL   
      void *TypData;         // Pointer auf die Typspezifischen Daten, NULL default will be filled with typ specific data   
      int Start;             // Start Bit, first bit to decode in word for this item   
      int Number;             // AnzahlBits number of bits to decode for this item   
    };
    


  • kingruedi schrieb:

    Shade Of Mine schrieb:

    und meine die C++ Loesung.

    nicht ganz

    sorry, seh den unterschied zwischen deinem und meinem code gerade nicht.



  • //Shade Of Mine
      struct BASESTRUCT *next; 
      struct BASESTRUCT *prev;
    
    //kingruedi 
      BASESTRUCT *next;
      BASESTRUCT *prev;
    


  • oh, bloeder copy&paste fehler

    danke 👍



  • Danke, hat mir ne Menge gebracht.


Anmelden zum Antworten