global variable in PhAB

where can you declare your global variable in PhAB so that all your callback functions can have access to it?

Thanks

See the “Global header file” section in the Working with Code chapter of the Photon Programmer’s Guide.

thanks will do~

I have read the documents and tried it but it’s not working. Here is my global.h file

#include <Pt.h>
#ifdef DEFINE_GLOBALS
#define GLOBAL
#define INIT(x) = x
#else
#define GLOBAL extern
#define INIT(x)
#endif
//global variables
GLOBAL int number INIT(0);

in only one of my callback function, I have added
#define DEFINE_GLOBALS
but when I try to use the number variable in any of my callback functions I get undefined error message during compile time. I have added global file information in PhAB and it seemed to generate the correct code in momentics. Any ideas? Do I have to define the “DEFINE_GLOBALS” in some specific callback function?

The #define DEFINE_GLOBALS needs to be in the include of global.h and not in the function.

Personnaly I don’t like this trick of having a single line of code be both definition for extern and declaration though a #define. Instead have global.h always define extern and put the variable somewhere in a C file (I like to create a global.c file or if applicable put it in the main.c )

Thanks a bunch~