Go Down

Topic: PROGMEM use in Arduino (Read 1 time) previous topic - next topic


I have a .h file with lots of entries like this:
Code: [Select]
static const char v1a[] PROGMEM="OUS_";
After several entries, there is an entry like this:
Code: [Select]
static const VOCAB PROGMEM s_vocab[] ={
     { v1a,  v1b} ,{ v2a,  v2b}, {  v3a,  v3b},{  v4a,  v4b},{  v5a,  v5b},{  v6a,  v6b},{  v7a,  v7b},{  v8a,  v8b},{  v9a,  v9b},{ v10a, v10b},..... and so on.... };

Then in the code, s_vocab is used.

When compiling, I get an error like this for every entry where PROGMEM is used:
Code: [Select]
C:\DOCUME~1\Gabi\LOCALS~1\Temp\build63463.tmp\/english.h:8: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'PROGMEM'

Then I get this error:
Code: [Select]
error: 's_vocab' undeclared (first use in this function) In function xxx

I have tried to make a library, but the s_vocab gets out of scope (I don't get the PROGMEM errors in this case).

Any advice would be very appreciate!



Fixed the original problem by reversing the position of the PROGMEM in the declaration, like this:
static const VOCAB s_vocab[] PROGMEM={...};

Now I have other errors.

In the  core.c file I have a struct like this:
Code: [Select]
typedef struct Vocab {
     const char* txt;
     const char* phoneme;

As I read about structs, I have a struct called Vocab with 2 members and an object VOCAB (I think...). Then, in the .h file I have the VOCAB declared as:

static const VOCAB s_vocab[] PROGMEM={....};

However, I get this error at compile:
Code: [Select]
C:\DOCUME~1\Gabi\LOCALS~1\Temp\build63463.tmp\/english.h:785: error: expected '=', ',', ';', 'asm' or '__attribute__' before 's_vocab'

If I add '=' like this:
static const VOCAB=s_vocab[] PROGMEM={....}

I get this errors:
Code: [Select]
C:\DOCUME~1\Gabi\LOCALS~1\Temp\build63463.tmp\/english.h:785: error: 's_vocab' undeclared here (not in a function)
C:\DOCUME~1\Gabi\LOCALS~1\Temp\build63463.tmp\/english.h:785: error: expected expression before ']' token
error: 'VOCAB' redeclared as different kind of symbolC:\DOCUME~1\Gabi\LOCALS~1\Temp\build63463.tmp\/english.h:785: error: previous definition of 'VOCAB' was here

and it highlights the end of the struct declaration in the .c file.

Any ideas how to fix this?

Thank you for any help!

Coding Badly

I'd like to help but I'm having problems understanding what goes where.  Can you put together a small example that illustrates the problem?


As I read about structs, I have a struct called Vocab with 2 members and an object VOCAB (I think...).

Not quite. You have a struct called Vocab with 2 members. You also have an alias for "struct Vocab" that is "VOCAB". This allows you to use "VOCAB" as the type where you would ordinarily have to use "struct Vocab" as the type.

It's a fairly conventional shorthand.

Can't help you on the rest of the questions/issues, though.
The art of getting good answers lies in asking good questions.


OK. I have talked with the author of the original code I'm trying to implement in Arduino. He can't help with the Arduino part, but he gave me permission to post the code and ask questions here.

So here is the link to the original code (see the bottom of the page):

And here is my attempt to make it work in Arduino:

Any help would be greatly appreciated!

Coding Badly

Brief: The header file english.h makes use of three types (VOCAB, PHONEME, and SOUND_INDEX).  These types are declared in core.c after the english.h file has been included.

Long: Essentially, the preprocessor starts with a source file (like core.c) and inserts the contents of each include file at the #include line.  In other words, english.h is inserted into core.c at the #include "english.h" line.  This puts the definitions of the three types after they are first referenced.

To solve the problem, I cut each type definition from "core.c" and pasted it at the top of "english.h"

Does that make sense?

Go Up