Go Down

Topic: forward declaration trouble with const in PROGMEM (Read 46 times) previous topic - next topic


I am currently porting some code written in 'c' to my arduino environment. It defines a structure which I want to use as a const residing in progmem:

The h-file:

Code: [Select]
#ifdef __cplusplus
extern "C" {

#include <stdint.h>

typedef struct{
    const uint8_t  attribs;
    // ... and some other variables here
} EmxFont_t;

#ifdef __cplusplus

In a c-file, I instantiate such a structure:

Code: [Select]

const PROGMEM EmxFont_t FontVerdana11 = {
     // Size: Header(12/0x000C)+Index(264/0x0108)+Maps(393/0x0189)=669/0x029D
    .attribs     = 0x80,  
    // ... and some other values here

This compiles fine.

If I want to use this 'FontVerdana11' constant in an *ino file:

Code: [Select]

extern const EmxFont_t FontVerdana11 PROGMEM;


lcdBufPuts("Hello, world!", &FontVerdana11, 0, 10, COL_BLACK);


But the compiler complains:

Code: [Select]

.../EMXArdu.ino:13:24: warning: type of 'FontVerdana11' does not match original declaration
 extern const EmxFont_t FontVerdana11 PROGMEM;
/tmp/arduino_build_356363/sketch/FontVerdana11.c:43:25: note: previously declared here
 const EmxFont_t FontVerdana11 PROGMEM= {

It is "only" a warning, but I would like to understand what's wrong here?


I would like to understand what's wrong here?
What is wrong is that you failed to post ALL of your code. We have no clue how you defined the variable in the .ino file.

Why are you using a .c extension, anyway? Using a .cpp extension is not REALLY that much more typing, and greatly simplifies the linking process.
The art of getting good answers lies in asking good questions.

Go Up