This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

'code U8 u8data' visible in all sources files ?

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, /* ! */
...
...
}

My graphic routines are located in a GLCD.C file.
In the GLCD.H, I've defined and declared structures like this :
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};

Using these structures in the GLCD.C file is working fine.


However, an other module which includes the GLCD.H file, should call a Graphic function located in the GLCD.C file which display text and pass the pointer to a font structure as parameter :
GLCD_Printf("Hello world", &FontSystem5x8);

But, an error message occurs when including GLCD.H :
***ÿERROR 202 IN LINE 35 OF GLCD.H: 'au8FontSystem5x8': undefined identifier

This means that the code defined in FONT.H isn't available for other modules than GLCD.C where it's included.

The problem is that I can't include FONT.H in all the modules because of multiple definition and code size.
But how to make this code visible everywhere.

I've tried :
extern code U8 au8FontSystem5x8[]= {
0x00,0x00,0x00,0x00,0x00, /* Espace	0x20 */
0x00,0x00,0x4f,0x00,0x00, /* ! */
...
...
}

without success


Any suggestion ?

Regards
Stephane

Parents
  • 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
    

    Then you can replace all your individual #ifdef's by calls to this macro:

    DEFINE_INITIALIZED(code u8, textstring[], "hello, again");

    OTOH, my personal preference is to avoid having initializers in the header file. This means you have to maintain the extern declaration and the actual definition in separate files, but the clarity is worth that.

Reply
  • 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
    

    Then you can replace all your individual #ifdef's by calls to this macro:

    DEFINE_INITIALIZED(code u8, textstring[], "hello, again");

    OTOH, my personal preference is to avoid having initializers in the header file. This means you have to maintain the extern declaration and the actual definition in separate files, but the clarity is worth that.

Children