Forum: Compiler & IDEs Probleme mit einer struct


von Otto Richter (Gast)


Lesenswert?

Hallo

ich habe ein Problem mit einer struct.

Ich habe sie (hoffentlich) global definiert:

/**** eeprom_handling.c   begonnen 5.2.06  OR  *****/

#include <stdint.h>
#include <stdio.h>
#include <avr/eeprom.h>

#ifndef EEPROM
#define EEPROM _attribute_ ((section (".eeprom")))
#endif

/* Definition der  struct und Füllen mit Werten */
struct
{
  uint8_t format_delay_control [ 3 ] ;
  uint8_t    chroma_gain_control [ 3 ];
  uint8_t    chroma_control [ 3 ];

}     eeprom_data = {{    0x11, 0xBB,0x33    } ,
                     {    0x44, 0x55, 0x66   } ,
                    {    0x77, 0x88, 0xFF   }} ;

eeprom_data.format_delay_control[ 0 ] = 0x00;    DIESE ZEILE GIBT DIE
gcc-FEHLERMELDUNG: parse error before '.' token


/* Funktion Schreiben des EEPROMs */
void eeprom_write ( void )
{
  eeprom_data.format_delay_control[ 0 ]++ ;  DAS GEHT KOMISCHERWEISE !
  eeprom_write_block ( &eeprom_data , 0  ,  sizeof ( eeprom_data ) ) ;
   }
/*Funktion  Lesen des EEPROMs */   DIE FUNKTIONIERT AUCH !
void eeprom_read ( void )
{
  eeprom_read_block ( &eeprom_data , 0  ,  sizeof ( eeprom_data ) ) ;
for (uint8_t i=0; i < sizeof ( eeprom_data.format_delay_control ); i++)
printf("%X",eeprom_data.format_delay_control[i]) ;
  for (uint8_t i=0; i < sizeof ( eeprom_data.chroma_gain_control );
i++) printf("%X",eeprom_data.chroma_gain_control[i]) ;
  for (uint8_t i=0; i < sizeof ( eeprom_data.chroma_control ); i++)
printf("%X",eeprom_data.chroma_control[i]) ;
}

ABER WENN ich dann in einer anderen Funktion auf einen Wert aus der
struct zugreifen will, z.B.  mit

  eeprom_data.format_delay_control[ 0 ]++ ;

BEKOMME ich die Fehlermeldung: 'eeprom_data' undeclared.

Das sieht doch ganz so aus, als wenn die struct nicht global wäre oder
?

Otto

(Danke für die Hilfe )

von Rufus Τ. F. (rufus) Benutzerseite


Lesenswert?

Befindet sich die "andere Funktion" im gleichen Sourcefile wie die
Deklaration und Defintion der Struktur?

Wenn nicht, dann musst Du eine Headerdatei verwenden und in dieser die
Struktur als "extern" deklarieren.

von Otto Richter (Gast)


Lesenswert?

Hallo Rufus,

Danke für die Hilfe, aber...

die Deklaration steht im gleichen Sourcefile, aber ich brauche die
Werte auch noch in anderen functions, die in anderen Sourcefiles
stehen.

Wie sieht denn die Deklaration  einer struct aus (bin Anfänger),
identisch wie im Programm ?

external struct
{
  uint8_t format_delay_control [ 3 ] ;
  uint8_t    chroma_gain_control [ 3 ];
  uint8_t    chroma_control [ 3 ];

}     eeprom_data = {{    0x11, 0xBB,0x33    } ,
                     {    0x44, 0x55, 0x66   } ,
                    {    0x77, 0x88, 0xFF   }} ;

Muss ich die Elemente wie "format_delay_control" mit aufnehmen, die
Deklaration der Werte brauche ich bestimmt nicht, oder ?

Danke

Otto

von Rufus Τ. F. (rufus) Benutzerseite


Lesenswert?

Damit das funktioniert, sollte die Struktur benannt werden:

Dann sieht das ganze so aus:

Headerdatei:

  struct eeprom_struct
  {
    uint8_t format_delay_control[3];
    uint8_t chroma_gain_control[3];
    uint8_t chroma_control[3];
  };

  extern struct eeprom_struct eeprom_data;

Sourcefile mit Definition:

  #include "wasauchimmer.h"

  struct eeprom_struct eeprom_data = { ... };


Anderes Sourcefile mit Zugriff:

  #include "wasauchimmer.h"

  ...

    // in irgendeiner Funktion
    eeprom_data.format_delay_control[0] = 7;


Viel Erfolg.

von Otto Richter (Gast)


Lesenswert?

Hallo Rufus,

...es wird mir langsam klar !

danke Dir  !!

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.