0

AVR-GCC: initializer element is not constant
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

AVR-GCC: initializer element is not constant

by uhe on Wed Sep 24, 2008 4:04 pm

Hi

maybe someone here knows an answer.. I have a little peace of code which starts like this:

Code: Select all | TOGGLE FULL SIZE
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/io.h>

typedef struct {const char foo;} const foobar;
const foobar fooA = {1};
const foobar fooB = {2};
const foobar bar[] PROGMEM = {fooA,fooB};

and then avr-gcc breaks with this error:

Code: Select all | TOGGLE FULL SIZE
v_7.c:23: error: initializer element is not constant
v_7.c:23: error: (near initialization for 'bar[0]')
v_7.c:23: error: initializer element is not constant
v_7.c:23: error: (near initialization for 'bar[1]')
make: *** [v_7.o] Fehler 1

Can someone enlighten me whats wrong with the declaration / initiation of the struct / array?
uhe
 
Posts: 178
Joined: Mon Sep 03, 2007 4:50 pm
Location: metric world

Re: AVR-GCC: initializer element is not constant

by mtbf0 on Wed Sep 24, 2008 6:49 pm

what is it that you're trying to do? pretty sure i'm more confused than the poor damned compiler. why try to turn otherwise happy scalar values into structures?

Code: Select all | TOGGLE FULL SIZE
const foobar bar[] PROGMEM = {fooA,fooB};


this is just wrong. the stuff between those braces must resolve to values and what you've got there are references. that might possibly work if you had it stuck within the body of a function, but i wouldn't want to bet anything on it.

perhaps you want

Code: Select all | TOGGLE FULL SIZE
#define fooA {1}
#define fooB {2}
const foobar bar[] PROGMEM = {fooA,fooB};
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

by uhe on Wed Oct 01, 2008 6:03 pm

Hi mtbf0,

you're right about the values.
Want i want to do is to store as much pattern as possible and besides of that, i want to *loop* through this pattern as generic as posible.
I've build just another LED-Cube (4x4x4) for fun and...
The pattern i want to store are the animations that should be displayed.
Its done now and i only need the two timers for displaying :)
The solution i've come up with is to have a struct for normal data and one for meta data. These are stored in two arrays.
Then in timer0 i can loop through all data with something like this:
Code: Select all | TOGGLE FULL SIZE
tmpVal = pgm_read_word(&(fDATA[inFraCnt])[dataCnt].level[levCnt]);

It's not that elegant i think but its very easy to loop through..
thx for your comments!
uhe
 
Posts: 178
Joined: Mon Sep 03, 2007 4:50 pm
Location: metric world

Please be positive and constructive with your questions and comments.