In SDCC #9994, I see the following error messages, when initalizing a void * from a different pointer type (there awas an error before, but in #9994 it was made more verbose to print the types involved).
static struct { unsigned char STK[128]; } s; void *v = &s + 1;
For the stm8 and z80 backends I see:
test.c:3: error 129: pointer types incompatible from type 'struct __00000000 near* fixed' to type 'void generic* fixed' test.c:3: error 129: pointer types incompatible from type 'struct __00000000 near* fixed' to type 'void generic* const fixed'
Which looks a bit weird, since there is no near in the stm8 and stm8 backends. All pointers should be generic.
For the hc08 backend I see:
test.c:3: error 129: pointer types incompatible from type 'struct __00000000 xdata* xdata' to type 'void generic* xdata' test.c:3: error 129: pointer types incompatible from type 'struct __00000000 xdata* xdata' to type 'void generic* const xdata'
And what is that 00000000?
Philipp
Even weirder, even the following gives silimar errors:
PHilipp
In this case:
there are no errors.
A closer look at the ISO C11 standard, section 6.6 indicates that SDCC does not have to accept '+' in address pointer constants. In that case the bug is not SDCC rejecting the code, but rather SDCC giving a wrong error message.
Philipp
In revision [r10036], I changed the default error message in initPointer() to complain about the expression not being constant instead of incompatible types.
Philipp
Does that mean your example is still an error?
I think section 6.6 explicitly mentions this case:
7 More latitude is permitted for constant expressions in initializers. Such a constant
expression shall be, or evaluate to, one of the following:
...
— an address constant for a complete object type plus or minus an integer constant
expression.
I was only looking at verse 9 of 6.6, but yes, verse 7 allows more. I'm not sure about the cast though.
But it seems SDCC should at least accept
So this bug is open again.
Philipp
Interesting example:
Last edit: Rajmund Szymański 2017-10-08
Not much of a surprise. The file-scope objects need constant expressions as initializers, the function-scope auto ones do not.
Even when this bug is fixed, still a lot more will be allowed for the function-scope auto ones, than for the file-scope ones.