Global Variable Placement

I’ve tried to insert global variables in various places in Kevin’s code only to get stack overflow, code errors (RC), sytax errors, compiler crashes and general system crashes. Where do you all put your global variables. I’m interested in global only. I’d like to minimise passing information between functions. Thanks

A good practice is to declare a variable outside of any function and then declare the variable as “extern” within the associated header file. So for example, at the top of teleop.c I declare a variable:

// this allocates memory
unsigned int foo;

Then in teleop.h I declare the variable again with the keyword extern:

// no memory is allocated, but lets the compiler know the name (foo)
// and type (unsigned int), and that it is located in another source file
extern unsigned int foo;

Then include teleop.h at the top of each source file that needs to use foo. The line will look like this:

#include “teleop.h”

-Kevin