(iPhone) Pulling my hair out just trying to declare and set a stupid variable. Here’s the code:
const GLfloat zNear = 0.01, zFar = 1000.0, fieldOfView = 60.0;
GLfloat size;
size = zNear * tanf(DEGREES_TO_RADIANS*fieldOfView / 2.0));
Gives me the error “Conflicting types for ‘size'”.
If I write it like this instead:
const GLfloat zNear = 0.01, zFar = 1000.0, fieldOfView = 60.0;
GLfloat size = zNear * tanf(DEGREES_TO_RADIANS*fieldOfView / 2.0));
I get the error, “Initializer element is not constant”.
What’s really weird is that this code worked fine when it was inside a method. I moved it out of the method, and now it fails. What’s going on here?
When dealing at global-scope, statements can be assigned to only constant literals.
The solution is
#define. Try this –