KEIL C51 Problem

Gast #986293
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;
#986755
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
Gast #986772
> 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

Antwort schreiben

Eine eigene Frage? Dieser Thread ist über 18 Jahre alt. Stell sie in einem eigenen Thread – dort lesen mehr Leute mit, und sie wird öfter und schneller beantwortet.

Neuen Thread starten

Eine Lösung, Ergänzung oder Rückmeldung zu diesem Thread? Dann antworte hier.

Formatierung
  • [c]C-Code[/c]
  • [code]Code in anderen Sprachen, ASCII-Zeichnungen[/code]
  • [math]Formel in LaTeX-Syntax[/math]
  • [[Titel]] – Link zu einem Artikel
  • Verweis auf einen anderen Beitrag: Rechtsklick auf dessen Beitrags-ID (#8078628), „Adresse kopieren“, in den Text einfügen

Mehr zur Formatierung

Längeren Sourcecode als Anhang, nicht in den Text. JPG nur für Fotos und Scans; Zeichnungen und Screenshots als PNG oder GIF. Siehe Bildformate.

Schon registriert? Anmelden

Wird nicht angezeigt. Wir schicken dir einen Link; sobald du damit bestätigst, erscheint dein Beitrag.

Mit dem Abschicken legst du einen kostenlosen Account an und erkennst die Nutzungsbedingungen und die Datenschutzerklärung an.