-
Struct Problem
I'm having a problem with a structure. I declare a structure in the file "Config.c" like this
Code:
struct setting{
int ScreenWidth;
int ScreenHeight;
};
struct setting *Settings;
Then I use this function to set values for ScreenHeight and ScreenWidth
Code:
InitSettings(){
Settings = calloc(1,sizeof(struct setting));
Settings->ScreenWidth = 1024;
Settings->ScreenHeight = 768;
}
Then I want to accses the struct from another file.
Code:
extern struct setting *Settings;
InitGUI(){
int GameWindowLeft;
GameWindowLeft = Settings->ScreenWidth - 320;
}
The problem is that I get this error message "dereferencing pointer to incomplete type "
-
Is the structure definition visible in the file that produces the error? Is this part in a header?
Code:
struct setting{
int ScreenWidth;
int ScreenHeight;
};
-
No the definition is in the file "config.h" and the file that produces the error is "Video.c".
-
Did you include "config.h" in "Video.c"? I'm guessing you have to do this because an extern isn't enough, since you're accessing one of the data members.
-
It works!!! I didn't have a clue that you had to include the header file when accsessing an external structure. I will remember that, thank you! :)
-
You have to tell the compiler what a user-defined data type "looks" like so that it "knows" whether you are using it correctly.