I have a C header file like this:
#ifndef RENDERER_H
#define RENDERER_H
static int g_count = 0;
static inline void g_addVertex(...) {
...
g_count++;
}
static inline void g_flush() {
...
g_count = 0;
}
#endif
I have an Objective-C class like this:
...
#include "Renderer.h"
@implementation Sprite
...
-(void)draw:(float)dt {
...
g_addVertex(...); //6 times
}
In the iOS OpenGL template in ES1Renderer.m I create a Sprite instance. In the render methon in ES1Renderer I call the draw method of this instance, and the g_count variable counts normally in the draw method.(Its value 6 after six g_addVertex(…) function call in draw)
But after I call the g_flush() function in the render method of the ES1Renderer, right after the Sprite instance draw method called, in the g_flush() the value of the g_count variable is 0.
It should be for example 6 after six g_addVertex() in draw method of the Sprite class.
Help me please i don’t know why the g_count change to 0, there is no other functions or something between them where i change its value.
A static variable is decidedly not global. A static variable has file scope and internal linkage, so each file that includes the header will get its own
g_count. If you want a global variable, just writeint g_countin one implementation file and putextern int g_countin a header that other files using that global variable will import.