Compilerfehler mit Header File



  • Hallo zusammen,
    Ich habe ein böses Problem welches ich nicht so ganz verstehe.

    Folgendes header file wirft bei mir die nachstehenden fehler:

    #ifndef GETPUT_H
    #define GETPUT_H
    
    /*------------ macros for storing/extracting msb first words -------------*/
    
    #define GET_32BIT(cp) (((unsigned long)(unsigned char)(cp)[0] << 24) | 
                           ((unsigned long)(unsigned char)(cp)[1] << 16) | 
                           ((unsigned long)(unsigned char)(cp)[2] << 8) | 
                           ((unsigned long)(unsigned char)(cp)[3]))
    
    #define GET_16BIT(cp) (((unsigned long)(unsigned char)(cp)[0] << 8) | 
                           ((unsigned long)(unsigned char)(cp)[1]))
    
    #define PUT_32BIT(cp, value) do { 
      (cp)[0] = (value) >> 24; 
      (cp)[1] = (value) >> 16; 
      (cp)[2] = (value) >> 8; 
      (cp)[3] = (value); } while (0)
    
    #define PUT_16BIT(cp, value) do { 
      (cp)[0] = (value) >> 8; 
      (cp)[1] = (value); } while (0)
    
    /*------------ macros for storing/extracting lsb first words -------------*/
    
    #define GET_32BIT_LSB_FIRST(cp) 
      (((unsigned long)(unsigned char)(cp)[0]) | 
      ((unsigned long)(unsigned char)(cp)[1] << 8) | 
      ((unsigned long)(unsigned char)(cp)[2] << 16) | 
      ((unsigned long)(unsigned char)(cp)[3] << 24))
    
    #define GET_16BIT_LSB_FIRST(cp) 
      (((unsigned long)(unsigned char)(cp)[0]) | 
      ((unsigned long)(unsigned char)(cp)[1] << 8))
    
    #define PUT_32BIT_LSB_FIRST(cp, value) do { 
      (cp)[0] = (value); 
      (cp)[1] = (value) >> 8; 
      (cp)[2] = (value) >> 16; 
      (cp)[3] = (value) >> 24; } while (0)
    
    #define PUT_16BIT_LSB_FIRST(cp, value) do { 
      (cp)[0] = (value); 
      (cp)[1] = (value) >> 8; } while (0)
    
    #endif /* GETPUT_H */
    
    "include/getput.h", line 46: zero or negative subscript
    "include/getput.h", line 46: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 46: undefined symbol: value
    "include/getput.h", line 46: warning: {}-enclosed initializer required
    "include/getput.h", line 46: too many array initializers
    "include/getput.h", line 47: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 47: identifier redefined: cp
            current : array[1] of int
            previous: array[-2] of int : "include/getput.h", line 46
    "include/getput.h", line 47: warning: {}-enclosed initializer required
    "include/getput.h", line 47: non-constant initializer: op ">>"
    "include/getput.h", line 48: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 48: identifier redefined: cp
            current : array[2] of int
            previous: array[1] of int : "include/getput.h", line 47
    "include/getput.h", line 48: warning: {}-enclosed initializer required
    "include/getput.h", line 48: non-constant initializer: op ">>"
    "include/getput.h", line 49: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 49: identifier redefined: cp
            current : array[3] of int
            previous: array[2] of int : "include/getput.h", line 48
    "include/getput.h", line 49: warning: {}-enclosed initializer required
    "include/getput.h", line 49: non-constant initializer: op "NAME"
    "include/getput.h", line 49: syntax error before or at: }
    "include/getput.h", line 52: zero or negative subscript
    "include/getput.h", line 52: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 52: identifier redefined: cp
            current : array[-2] of int
            previous: array[3] of int : "include/getput.h", line 49
    "include/getput.h", line 52: warning: {}-enclosed initializer required
    "include/getput.h", line 52: too many array initializers
    "include/getput.h", line 53: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 53: identifier redefined: cp
            current : array[1] of int
            previous: array[-2] of int : "include/getput.h", line 52
    "include/getput.h", line 53: warning: {}-enclosed initializer required
    "include/getput.h", line 53: non-constant initializer: op "NAME"
    "include/getput.h", line 53: syntax error before or at: }
    "include/getput.h", line 58: syntax error before or at: unsigned
    "include/getput.h", line 58: zero or negative subscript
    "include/getput.h", line 58: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 58: identifier redeclared: cp
            current : array[-2] of int
            previous: array[1] of int : "include/getput.h", line 53
    "include/getput.h", line 58: syntax error before or at: )
    "include/getput.h", line 58: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 58: identifier redeclared: cp
            current : array[1] of int
            previous: array[-2] of int : "include/getput.h", line 58
    "include/getput.h", line 58: syntax error before or at: <<
    "include/getput.h", line 58: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 58: identifier redeclared: cp
            current : array[2] of int
            previous: array[1] of int : "include/getput.h", line 58
    "include/getput.h", line 58: syntax error before or at: <<
    "include/getput.h", line 58: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 58: identifier redeclared: cp
            current : array[3] of int
            previous: array[2] of int : "include/getput.h", line 58
    "include/getput.h", line 58: syntax error before or at: <<
    "include/getput.h", line 61: syntax error before or at: unsigned
    "include/getput.h", line 61: zero or negative subscript
    "include/getput.h", line 61: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 61: identifier redeclared: cp
            current : array[-2] of int
            previous: array[3] of int : "include/getput.h", line 58
    "include/getput.h", line 61: syntax error before or at: )
    "include/getput.h", line 61: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 61: identifier redeclared: cp
            current : array[1] of int
            previous: array[-2] of int : "include/getput.h", line 61
    "include/getput.h", line 61: syntax error before or at: <<
    "include/getput.h", line 64: zero or negative subscript
    "include/getput.h", line 64: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 64: identifier redeclared: cp
            current : array[-2] of int
            previous: array[1] of int : "include/getput.h", line 61
    "include/getput.h", line 64: warning: {}-enclosed initializer required
    "include/getput.h", line 64: too many array initializers
    "include/getput.h", line 65: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 65: identifier redefined: cp
            current : array[1] of int
            previous: array[-2] of int : "include/getput.h", line 64
    "include/getput.h", line 65: warning: {}-enclosed initializer required
    "include/getput.h", line 65: non-constant initializer: op ">>"
    "include/getput.h", line 66: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 66: identifier redefined: cp
            current : array[2] of int
            previous: array[1] of int : "include/getput.h", line 65
    "include/getput.h", line 66: warning: {}-enclosed initializer required
    "include/getput.h", line 66: non-constant initializer: op ">>"
    "include/getput.h", line 67: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 67: identifier redefined: cp
            current : array[3] of int
            previous: array[2] of int : "include/getput.h", line 66
    "include/getput.h", line 67: warning: {}-enclosed initializer required
    "include/getput.h", line 67: non-constant initializer: op ">>"
    "include/getput.h", line 67: syntax error before or at: }
    "include/getput.h", line 70: zero or negative subscript
    "include/getput.h", line 70: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 70: identifier redefined: cp
            current : array[-2] of int
            previous: array[3] of int : "include/getput.h", line 67
    "include/getput.h", line 70: warning: {}-enclosed initializer required
    "include/getput.h", line 70: too many array initializers
    "include/getput.h", line 71: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 71: identifier redefined: cp
            current : array[1] of int
            previous: array[-2] of int : "include/getput.h", line 70
    "include/getput.h", line 71: warning: {}-enclosed initializer required
    "include/getput.h", line 71: non-constant initializer: op ">>"
    "include/getput.h", line 71: syntax error before or at: }
    

    Als compiler benutze ich den cc auf einer Sparc Solaris.

    Ich hoffe jemand von euch kann mir hier helfen, ich verzweifle beinahe.



  • #define GET_32BIT(cp) (((unsigned long)(unsigned char)(cp)[0] << 24) | \
                           ((unsigned long)(unsigned char)(cp)[1] << 16) | \
                           ((unsigned long)(unsigned char)(cp)[2] << 8) | \
                           ((unsigned long)(unsigned char)(cp)[3]))\
    


  • Hab ich mal gemacht, aber habe dennoch immer noch genau die selben fehler... Noch andere Ideen?



  • Der Präprozessor arbeitet zeilenweise (im Gegensatz zum Compiler), deshalb werden die Fortsetzungszeilen nicht mehr zu den jeweiligen Makros zugeordnet. Wenn du eine Makro-Definition über mehrere Zeilen verteilen willst, mußt du mit einem \ am Ende kennzeichnen, daß die aktuelle Zeile (logisch) weitergeht - und das bei allen deinen mehrzeiligen Makro-Definitionen.

    (PS: Ich hoffe mal, das ist nur ein Ausschnitt des kompletten Files - die Zeilenangaben der Fehlermeldungen passen nämlich nicht ganz dort rein)



  • Wie war denn die Vorgeschichte dieser Fehlermeldungen? Sind sie einfach plötzlich vom Himmel gefallen?



  • So, hier noch einaml das angepasste file, sowie die neuen Fehlermeldungen. was hat das nun zu bedeuten?

    #ifndef GETPUT_H
    #define GETPUT_H
    
    /*------------ macros for storing/extracting msb first words -------------*/
    
    #define GET_32BIT(cp) (((unsigned long)(unsigned char)(cp)[0] << 24) | \
                           ((unsigned long)(unsigned char)(cp)[1] << 16) | \
                           ((unsigned long)(unsigned char)(cp)[2] << 8) | \
                           ((unsigned long)(unsigned char)(cp)[3]))\
    
    #define GET_16BIT(cp) (((unsigned long)(unsigned char)(cp)[0] << 8) | \
                           ((unsigned long)(unsigned char)(cp)[1])) \
    
    #define PUT_32BIT(cp, value) do { \
      (cp)[0] = (value) >> 24; \
      (cp)[1] = (value) >> 16; \
      (cp)[2] = (value) >> 8; \
      (cp)[3] = (value); } while (0)\
    
    #define PUT_16BIT(cp, value) do { \ 
      (cp)[0] = (value) >> 8; \
      (cp)[1] = (value); } while (0) \
    
    /*------------ macros for storing/extracting lsb first words -------------*/
    
    #define GET_32BIT_LSB_FIRST(cp) 
      (((unsigned long)(unsigned char)(cp)[0]) | \
      ((unsigned long)(unsigned char)(cp)[1] << 8) | \
      ((unsigned long)(unsigned char)(cp)[2] << 16) | \
      ((unsigned long)(unsigned char)(cp)[3] << 24)) \
    
    #define GET_16BIT_LSB_FIRST(cp) 
      (((unsigned long)(unsigned char)(cp)[0]) | \
      ((unsigned long)(unsigned char)(cp)[1] << 8)) \
    
    #define PUT_32BIT_LSB_FIRST(cp, value) do { \
      (cp)[0] = (value); \
      (cp)[1] = (value) >> 8; \ 
      (cp)[2] = (value) >> 16; \ 
      (cp)[3] = (value) >> 24; } while (0) \
    
    #define PUT_16BIT_LSB_FIRST(cp, value) do { \
      (cp)[0] = (value); \
      (cp)[1] = (value) >> 8; } while (0)\
    
    #endif /* GETPUT_H */
    
    "include/getput.h", line 56: zero or negative subscript
    "include/getput.h", line 56: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 56: undefined symbol: value
    "include/getput.h", line 56: warning: {}-enclosed initializer required
    "include/getput.h", line 56: too many array initializers
    "include/getput.h", line 56: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 56: identifier redefined: cp
            current : array[1] of int
            previous: array[-2] of int : "include/getput.h", line 56
    "include/getput.h", line 56: warning: {}-enclosed initializer required
    "include/getput.h", line 56: non-constant initializer: op "NAME"
    "include/getput.h", line 57: syntax error before or at: }
    "include/getput.h", line 62: syntax error before or at: unsigned
    "include/getput.h", line 62: zero or negative subscript
    "include/getput.h", line 62: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 62: identifier redeclared: cp
            current : array[-2] of int
            previous: array[1] of int : "include/getput.h", line 56
    "include/getput.h", line 62: syntax error before or at: )
    "include/getput.h", line 62: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 62: identifier redeclared: cp
            current : array[1] of int
            previous: array[-2] of int : "include/getput.h", line 62
    "include/getput.h", line 63: syntax error before or at: <<
    "include/getput.h", line 63: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 63: identifier redeclared: cp
            current : array[2] of int
            previous: array[1] of int : "include/getput.h", line 62
    "include/getput.h", line 64: syntax error before or at: <<
    "include/getput.h", line 64: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 64: identifier redeclared: cp
            current : array[3] of int
            previous: array[2] of int : "include/getput.h", line 63
    "include/getput.h", line 65: syntax error before or at: <<
    "include/getput.h", line 68: syntax error before or at: unsigned
    "include/getput.h", line 68: zero or negative subscript
    "include/getput.h", line 68: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 68: identifier redeclared: cp
            current : array[-2] of int
            previous: array[3] of int : "include/getput.h", line 64
    "include/getput.h", line 68: syntax error before or at: )
    "include/getput.h", line 68: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 68: identifier redeclared: cp
            current : array[1] of int
            previous: array[-2] of int : "include/getput.h", line 68
    "include/getput.h", line 69: syntax error before or at: <<
    "include/getput.h", line 74: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 74: identifier redeclared: cp
            current : array[2] of int
            previous: array[1] of int : "include/getput.h", line 68
    "include/getput.h", line 74: warning: {}-enclosed initializer required
    "include/getput.h", line 74: non-constant initializer: op ">>"
    "include/getput.h", line 74: invalid source character: '\'
    "include/getput.h", line 75: warning: old-style declaration or incorrect type for: cp
    "include/getput.h", line 75: identifier redefined: cp
            current : array[3] of int
            previous: array[2] of int : "include/getput.h", line 74
    "include/getput.h", line 75: warning: {}-enclosed initializer required
    "include/getput.h", line 75: non-constant initializer: op ">>"
    "include/getput.h", line 75: syntax error before or at: }
    


  • Hinter diese letzten Zeilen vom define kommt natürlich kein \ mehr 😉

    Quasi

    #define PUT_32BIT(cp, value) do { \
      (cp)[0] = (value) >> 24; \
      (cp)[1] = (value) >> 16; \
      (cp)[2] = (value) >> 8; \
      (cp)[3] = (value); } while (0)
    

    anstatt

    #define PUT_32BIT(cp, value) do { \
      (cp)[0] = (value) >> 24; \
      (cp)[1] = (value) >> 16; \
      (cp)[2] = (value) >> 8; \
      (cp)[3] = (value); } while (0)\
    


  • Auch auf die Gefahr hin, mich selbst zu zitieren:

    CStoll schrieb:

    (PS: Ich hoffe mal, das ist nur ein Ausschnitt des kompletten Files - die Zeilenangaben der Fehlermeldungen passen nämlich nicht ganz dort rein)

    Wo in dem geposteten Ausschnitt liegt denn die Zeile 56?



  • Ja stimmt, es war eigentlich das komplette File, aber die ersten paar Zeilen habe ich weggelassen, da dort nur irgendwelche definitionen als kommentar stehen.

    Na ja, es funktioniert jetzt, nachdem ich das File noch einmal komplett neu kopiert habe, sowie anschliessend die \ wie von feigling beschrieben eingefügt habe.

    Vielen Dank auf jeden fall für eure schnelle Hilfe, es hat mir viel Ärger erspart.


Anmelden zum Antworten