Author Topic: Strange error when using a custom struct  (Read 4442 times)

Arenth

  • Guest
Strange error when using a custom struct
« on: April 21, 2005, 02:57:15 am »
Code

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.

Offline EricBurnett

  • Multiple posting newcomer
  • *
  • Posts: 20
    • http://
Strange error when using a custom struct
« Reply #1 on: April 21, 2005, 06:46:19 am »
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.

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Strange error when using a custom struct
« Reply #2 on: April 21, 2005, 08:25:03 am »
First, you have a typo (maybe a copy-paste error, but nonetheless):
Code
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.:
Code
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:
Code
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...