You DECLARE extern global variables in the header file.
You DEFINE the same variables and initialize the const variables in One .c file, and then use them in any .c file that #includes the header file.
Variables are usually given lower case names. "tile_size" rather than "TILE_SIZE". #defines are traditionally all upper case names.
We try to avoid global variables, and define them as local in main() or some other function and pass them to a function called.
Yes, you could use #defines in the header file instead of const variables:
Code:
#define TILE_SIZE 50
// ...
Please look at the following:
foo.h
Code:
#ifndef FOO_H
#define FOO_H
// extern DECLARATION only, defined in a .c file
extern const int SCREEN_WIDTH;
extern const int SCREEN_HEIGHT;
extern const int MAZE_WIDTH;
extern const int MAZE_HEIGHT;
extern const int TILE_SIZE;
// extern function declarations/prototypes
#endif // FOO_H
foo.c
Code:
#include <stdio.h>
#include "foo.h"
// Const variable DEFINITIONS
const int SCREEN_WIDTH = 500;
const int SCREEN_HEIGHT = 500;
const int MAZE_WIDTH = 21;
const int MAZE_HEIGHT = 21;
const int TILE_SIZE = 50;
int main(void)
{
printf("TILE_SIZE: %d\n", TILE_SIZE);
// ...
return 0;
}