Initializer: Pointer plus integer constant expression

Bug reports (if you don't/won't have a Github account)
Post Reply
tr1p1ea
New member
Posts: 2
Joined: Fri Feb 21, 2020 3:57 am

Initializer: Pointer plus integer constant expression

Post by tr1p1ea »

Not sure if this is the right place to post however I'm getting an issue with creating an array of pointers to some data like so:

Using v1.99C - zcc +embedded -vn -clib=new test.c -o test

Code: Select all

#define SIZE 4
uint8_t data[] = {0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3};
uint16_t *frames[] = {data+(SIZE*0),data+(SIZE*1),data+(SIZE*2),data+(SIZE*3)};
Error:Missing token, expecting } got +
Encasing each element like so (data+(SIZE*0)) throws:
Error:Expecting constant expression
Does it assume that the symbol is unreliable at compile time or something?

Even doing data+0 throws the error.
Timmy
Member
Posts: 136
Joined: Sat Mar 10, 2012 4:18 pm

Post by Timmy »

note: im not part of the z88dk team so my answers could be wrong...

But... "uint16_t *frames[]" doesn't seems (to me) to be an array of pointers to me though. If you ask me, that looks more like a pointer to an (uninitalised) array.

As for that data variable, I think that's normal in this Small C dialect, in which you can't use "data" at compile time. You can likely initialise the variable in run-time instead.
User avatar
dom
Well known member
Posts: 1194
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

It's a lack of parsing ability with handling initialisation with sccz80. I'll fix it in the next few days. To get you moving on, you could switch to -clib=sdcc_ix or -clib=sdcc_iy which will use sdcc as the compiler which does understand that syntax.
User avatar
dom
Well known member
Posts: 1194
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

This issue should be resolved in the next nightly build.

Thanks for reporting!
tr1p1ea
New member
Posts: 2
Joined: Fri Feb 21, 2020 3:57 am

Post by tr1p1ea »

Awesome, thanks very much!
stefano
Well known member
Posts: 1534
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

Awesome really. Well done Dom, you really stepped up at an higher level !
Post Reply