News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

Strange error when using a custom struct

Started by Arenth, April 21, 2005, 02:57:15 AM

Previous topic - Next topic

Arenth


struct GLF_Header {
   unsigned short int charCount;
   unsigned long int ColorKey;
};

struct GLFEntry {
   unsigned char charCode;
   unsigned long int xPos;
   unsigned long int yPos;
   unsigned long int Width;
   unsigned long int Height;
};


GLF_Header GLFH;
GLF_Entry GLFE[256];


Well thats my code, and these are my errors

Quote
GFX_Routines.c:20: parse error before "GLFH"
GFX_Routines.c:20: warning: data definition has no type or storage class
GFX_Routines.c:21: parse error before "GLFE"
GFX_Routines.c:21: warning: data definition has no type or storage class

Now my problem is, is to me, this code all looks completely ok, but for some reason, I get these errors, any help would be great.

EricBurnett

Could it be that the "unsigned short int" and such aren't recognised properly? You could try your code with just "unsigned short" and see what happens.

mandrav

First, you have a typo (maybe a copy-paste error, but nonetheless):
struct GLFEntry { .. }
GLF_Entry GLFE[256];


My guess is that this file has a .c extension, which makes the compiler treat it as a C file, not C++. This, in turn, means that you must program "the C way", i.e.:
struct GLF_Header { ... }
struct GLF_Entry { ... }

struct GLF_Header GLFH; // <-- notice the 'struct' keyword
struct GLF_Entry GLFE[256]; // <-- here too

or if you don't want to use the 'struct' keyword:
struct GLF_Header { ... }
typedef struct GLF_Header GLF_Header; // <-- 'typedef' it

struct GLF_Entry { ... }
typedef struct GLF_Entry GLF_Entry;  // <-- 'typedef' it

// since the structs are "typedef'd" now, you 're OK with this
GLF_Header GLFH;
GLF_Entry GLFE[256];



Your other option, is to rename the file to .cpp so the compiler treats it as a C++ file...

Yiannis.
Be patient!
This bug will be fixed soon...