Hi all, I've a file named FONT.H where are located some text fonts in code. They are defined and initialized like this:
code U8 au8FontSystem5x8[]= { 0x00,0x00,0x00,0x00,0x00, /* Espace 0x20 */ 0x00,0x00,0x4f,0x00,0x00, /* ! */ ... ... }
typedef struct FONT_DEF { U8 u8Width; /* Character width for storage */ U8 u8Height; /* Character height for storage */ U8 *au8FontTable; /* Font table start address in memory */ } FONT_DEF; struct FONT_DEF *pptr; extern struct FONT_DEF code Font_System5x8 = {5, 8, au8FontSystem5x8}; extern struct FONT_DEF code Font_System7x8 = {7, 8, au8FontSystem7x8};
GLCD_Printf("Hello world", &FontSystem5x8);
***ÿERROR 202 IN LINE 35 OF GLCD.H: 'au8FontSystem5x8': undefined identifier
extern code U8 au8FontSystem5x8[]= { 0x00,0x00,0x00,0x00,0x00, /* Espace 0x20 */ 0x00,0x00,0x4f,0x00,0x00, /* ! */ ... ... }
Check the distinction between a declaration and a definition Your headers should contain only declarations
While no exactly answering your question, here is how I do it. everything.h: #if MAIN #define XXX extern #else #define XXX XXX U8 a_variable; #if MAIN code u8 text_string[]{hello again}; #else extern code U8 text_string; main.c #define MAIN #include "everything.h" ... other.c #include "everything.h" ... Erik
I understand that you use a condition to put or not the 'extern' command. When including the *.h file from an other module, the datas in code are then declared as extern. But when always setting to 'extern', the datas in code are not seen in my other module. I don't understand why it isn't, and I don't understand how your code above will solve it... What have I missed ? Stephane
... Please no that this has absolutely no relevance to Keil tools --- you're asking very basic questions about C, which you should have learned from your textbook of choice, or ask about elsewhere. The key is that you have "extern" declarations (_not_ definitions) in the .h file, and actual definitions (usually without "extern") in exactly one of the .C files. e.g. foo.h:
extern int variable;
#include "foo.h" /*...*/ int variable = 5;
Extracting from my previous post
#if MAIN code u8 text_string[]{hello again}; #else extern code U8 text_string; #endif
Thanks for all these informations. I won't post any message which doesn't concern Keil tools. I'm sorry. Stephane REY
Hey, no need to apologize -- your code uses the Keil keyword code, so you see, it was relevant to Keil tools after all. But really, where to place defs vs. decls is a pretty general 'C' thing.
Well, if you really want to pursue that old trick... here's how you can do even better than that: In the header file for 'main.c', you would have this after all #includes of other files, but before any of the variables and functions:
#ifdef WE_ARE_COMPILING_MAIN_C # define DEFINE_INITIALIZED(type, name, ini) type name = ini #else # define DEFINE_INITIALIZED(type, name, ini) extern type name #endif
DEFINE_INITIALIZED(code u8, textstring[], "hello, again");
Take a look at the following knowledgebase article that addresses that very topic: http://www.keil.com/support/docs/1868.htm Jon