Mail Archives: djgpp/1998/02/07/13:03:03
Bruce Merry (the Almighty Cheese) (bmerry DOT nospam AT iafrica DOT com) wrote:
: Hi
: I've been using C and C++ for quite a while now, but up to now I've not
: needed to share a variable between source files. What I am trying at the
: moment is basically (with other stuff removed):
There are are several ways around this. One is:
: c_types.h:
: #ifndef __my_c_types_h
: #define __my_c_types_h
: typedef unsigned char byte;
: #endif
: kbd.h:
: #ifndef __my_kbd_h
: #define __my_kbd_h
#ifndef EXTERN
#define EXTERN extern
#endif
: #include "c_types.h"
EXTERN byte keys[128];
: #endif
: program.c:
#define EXTERN /* defined in one source file only */
: #include "c_types.h"
: #include "kbd.h"
: /* stuff with the keys array */
: kbd.c:
: #include "c_types.h"
: static volatile byte keys[128];
/* I'm lost here; why have you declared keys[] static if you
* want them to be accessible from other compilation units?
* And why a volatile array? volatile is mostly used for
* i/o addresses, to avoid unwanted optimisation. keys[]
* is just storage (AFAIK) for data once it's been read.
* Omit this line and include kbd.h to handle the declaration.
* You also need to decide whether to include all headers by
* name in source files, or include headers within headers, and
* then stick to one convention to avoid confusion.
*/
: /* code for keyboard handling */
: Basicly, all the source files compile into objects fine, but at link
: time the error 'undefined reference to keys' multiple times. What am I
: doing wrong (I'm using DJGPP 2, BTW).
: Thanks in advance
: Bruce
Will
cwr AT crash DOT cts DOT com
- Raw text -