Union



  • Hallo,

    wenn ich folgenden Datentyp definiere

    t.h:
    namespace test{
     typedef union
     {
      double f;
      long l;
      struct
      {
        unsigned int mant1 :32;
        unsigned int mant0 :20;
       } atyp;
     } btyp;
    }
    
    t.cpp:
    namespace test{
     double func(double c){
      btyp b;
      return c;
     }
    }
    

    und packe die Datei t in eine Lib., dann bekomme ich beim Linken der Lib mit
    einem Programm ein "undefined reference to `func'". Woran kann das liegen?

    Gruß
    Boris



  • Definier die Funktion doch in der Header Datei? Mehr sagt diese Fehlermeldung doch gar nichts aus.

    MFG Lars



  • Sorry, das habe ich vergessen anzugeben, ändert aber nichts an der Situation. Korrekt sollte es dann so sein

    t.h:
    namespace test{
     double func(double);
     typedef union
     {
      double f;
      long l;
      struct
      {
        unsigned int mant1 :32;
        unsigned int mant0 :20;
       } atyp;
     } btyp;
    }
    
    t.cpp:
    namespace test{
     double func(double c){
      btyp b;
      return c;
     }
    }
    


  • hjdt schrieb:

    Sorry, das habe ich vergessen anzugeben, ändert aber nichts an der Situation. Korrekt sollte es dann so sein

    t.h:
    namespace test{
     double func(double);
     typedef union
     {
      double f;
      long l;
      struct
      {
        unsigned int mant1 :32;
        unsigned int mant0 :20;
       } atyp;
     } btyp;
    }
    
    t.cpp:
    namespace test{
     double func(double c){
      btyp b;
      return c;
     }
    }
    

    Also das einzige was mir jetzt einfällt dass diesen Fehler produziert ist, wenn man vergisst das cpp file mit zur Bibliothek zu linken
    Anders könnte ich mir das gerade nicht erklären.

    BR



  • Das dachte ich mir auch, aber die die Datei habe ich in die Lib einkompiliert. Nehme ich die Union raus, geht es. Das ist schon sehr eigenartig.



  • ISO/IEC 14882:1998 schrieb:

    9.5.2 A union of the form

    *union { member-specification };

    is called an anonymous union; it defines an unnamed object of unnamed type. The member-specification of an anonymous union shall only define non static data members. [.[i]Note:* nested types and functions cannot be declared within an anonymous union. ] The names of the members of an anonymous union shall be distinct from the names of any other entity in the scope in which the anonymous union is declared. [...]

    Gib' der union mal einen Namen:

    typedef union __btyp {
        double f;
        long l;
        struct {
            unsigned int mant1 :32;
            unsigned int mant0 :20;
       } atyp;
    } btyp;
    

    Greetz, Swordfish


Anmelden zum Antworten