Forum: Mikrocontroller und Digitale Elektronik KEIL C51 Problem


von yoshi (Gast)


Lesenswert?

Guten Abend!

Ich wollte den Sourcecode vom GPS-Logger Projekt auf einen 8051er 
portieren. (51 COMPILER V7.05)
Jetzt kriege ich noch einen Fehler beim kompilieren. Und zwar:

syntax error near 'File'

auf der Zeile:
1
File logFile;


Meine Frage: wie werden beim KEIL compiler Strukturen richtig 
geschriben?
Momentan sieht die 'File' Struktur so aus:
1
typedef struct afile
2
{
3
  unsigned long   start_cluster;        // Sectorpointer to the first sector of the first datacluster of the file. 
4
  unsigned long   cluster_pointer;      // Pointer to the cluster which is edited at the moment.
5
  unsigned char   sector_index;        // The sector which is edited at the moment (cluster_pointer + sector_index).
6
  unsigned int    byte_index;          // The bytelocation within the current sector (cluster_pointer + sector_index + byte_index).
7
  unsigned char   mode;            // mode of fileoperation (read,write)
8
  unsigned long  filesize;          // the size of the opend file in bytes.
9
  unsigned long  fileposition;        // pointer to a character within the file 0 < fileposition < filesize
10
  unsigned long  sector_in_buffer;      // the last sector read, wich is still in the sectorbuffer.
11
  unsigned long  directory_sector;      // the sectorposition where the directoryentry has been made.
12
  unsigned char  directory_index;      // the index to the directoryentry within the specified sector.
13
  unsigned char  attribute;          // the attribute of the file opened.
14
} File;

von R. W. (quakeman)


Lesenswert?

Also die Definition eines Struct in C51 laut Handbuch würde fast genauso 
aussehen wie du es gemacht hast nur ohne das typedef und das File:
1
struct afile
2
{
3
  unsigned long  start_cluster;        // Sectorpointer to the first sector of the first datacluster of the file. 
4
  unsigned long  cluster_pointer;      // Pointer to the cluster which is edited at the moment.
5
  unsigned char  sector_index;        // The sector which is edited at the moment (cluster_pointer + sector_index).
6
  unsigned int   byte_index;          // The bytelocation within the current sector (cluster_pointer + sector_index + byte_index).
7
  unsigned char  mode;            // mode of fileoperation (read,write)
8
  unsigned long  filesize;          // the size of the opend file in bytes.
9
  unsigned long  fileposition;        // pointer to a character within the file 0 < fileposition < filesize
10
  unsigned long  sector_in_buffer;      // the last sector read, wich is still in the sectorbuffer.
11
  unsigned long  directory_sector;      // the sectorposition where the directoryentry has been made.
12
  unsigned char  directory_index;      // the index to the directoryentry within the specified sector.
13
  unsigned char  attribute;          // the attribute of the file opened.
14
};


Und die Initialisierung einer Variable samt einem Datensatz würde für 
dein Beispiel folgendermassen aussehen:
1
struct afile data info[1]={1,2,"3",4,"5",6,7,8,9,"10","11"};
Dabei steht data nur für den Speicherbereich in dem die Variable 
angelegt wird. Und die 11 Werte hintendran entsprechen deinen 11 Feldern 
des Struct.

Ich habe bisher selber noch nie einen Struct verwendet, weshalb diese 
Informationen alleine aus dem Handbuch stammen. Aber ich hoffe, ich habe 
mich nirgends verschrieben. ;)

Ciao,
      Rainer

von Ralf (Gast)


Lesenswert?

> syntax error near 'File'
Das deutet beim C51 drauf hin, dass der Fehler weiter oben liegt. 
Entweder fehlt ein Prototyp oder die Bekanntmachung von FILE oder eines 
anderen Typs (z.B. durch fehlende includes).

Ralf

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.