1: Sample code that reproduces the problem.
/* N3886 6.5.7p2: the other operand of pointer addition is integer. */
int *pointer;
float floating;
int *test1(void) {
return pointer + floating; /* ERROR */
}
/* N3886 6.5.7p3: pointer subtraction requires compatible pointed-to types. */
int *pointer;
char *other;
long test2(void) {
return pointer - other; /* ERROR */
}
/* N3886 6.5.7p3: pointed-to object types must also be complete. */
struct incomplete;
struct incomplete *left, *right;
long test3(void) {
return left - right; /* ERROR */
}
2: Exact command used to run SDCC on this sample code
./bin/sdcc -c bug.c
3: SDCC version tested
mcs51/z80/z180/r2k/r2ka/r3ka/r4k/r5k/r6k/sm83/tlcs90/ez80/z80n/r800/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15/mos6502/mos65c02/huc6280/f8/f8l TD- 4.6.2 #0 (macOS ARM64)
4: Copy of the error message or incorrect output, or a clear description of the observed versus expected behavior.
Every arithmetic operation violates a constraint. According to the ISO C standard, all constraint violations must be diagnosed. Clang, GCC and TCC report the constraint violations but SDCC does not. See https://godbolt.org/z/M1azch6Kd
Arithmetic on type
void *also violates the ISO C constraint. Clang reports 'warning: arithmetic on pointers to void is a GNU extension [-Wgnu-pointer-arith]' for arithmetic on typevoid *. It's not clear to me whether SDCC deliberately permits this behaviour as an extension or not. Strictly speaking, it should still produce a diagnostic in some kind of strict mode (if it has one).Currently it is (intentionally) allowed, but the (for some cases) missing warnings are a bug. A patch is being discussed at [bugs:#4056]
Related
Bugs:
#4056Last edit: Maarten Brock 2026-10-04
I'm attaching the relevant one of five candidate patches for bugs 4085...4089.
For testing purposes, all five were applied in numeric order to the baseline of f68fca8a4368ece9fe93b21f2e0341282b104359 from the git mirror. The following commands then completed successfully:
Test results:
Last edit: Christopher Bazley 6 days ago