Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: Arenth on April 21, 2005, 02:57:15 am

Title: Strange error when using a custom struct
Post by: Arenth 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.
Title: Strange error when using a custom struct
Post by: EricBurnett 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.
Title: Strange error when using a custom struct
Post by: mandrav 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.