I'm working through some openGL tutorials and since they all have C++ syntax I need to convert them to C syntax and I have some problems with global variables.
So I have my extern
declarations in the shared header LUtil.h
#ifndef LUTIL_H
#define LUTIL_H
#include "LOpenGL.h"
#include <stdio.h>
#include <stdbool.h>
//Color modes
extern const int COLOR_MODE_CYAN;
extern const int COLOR_MODE_MULTI;
//Screen constants
extern const int SCREEN_WIDTH;
extern const int SCREEN_HEIGHT;
extern const int SCREEN_FPS;
extern int gColorMode;
extern GLfloat gProjectionScale;
...
And I have my LUtil.c file in which the declaration happens
#include "LUtil.h"
//The current color rendering mode
const int COLOR_MODE_CYAN = 0;
const int COLOR_MODE_MULTI = 1;
//constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_FPS = 60;
//The projection scale
int gColorMode = 0;
GLfloat gProjectionScale = 1.f;
...
Now if I compile like this it works. But if I initialize the gColorMode constant like this in LUtil.c
int gColorMode = COLOR_MODE_CYAN;
I get a compiler error saying that my initializer is not constant despite having declared COLOR_MODE_CYAN
a const
and initializing with it.
Why is this?