1: Sample code that reproduces the problem
extern void sink(char *);
static char array[64];
int test(void)
{
char (*p)[64] = &array;
sink(*p++);
return p == &array + 1;
}
2: Exact command used to reproduce the problem
sdcc -mz80 --std-c99 --nostdinc -S bug.c -o bug.asm
3: SDCC version tested
SDCC 4.6.4 #17140 (Linux), tested on 8 November 2026.
4: Observed and expected behaviour
test should return 1 if sink returns normally without undefined behaviour. The generated code instead compares array + 1 with array + 64, so it returns 0. The complete generated body of test is:
_test::
ld hl, #_array
call _sink
ld hl, #_array + 1
ld de, #(_array + 64)
xor a, a
sbc hl, de
jr nz, 00104$
inc a
00104$:
ld e, a
ld d, #0x00
ret
p points to an array of 64 characters. Incrementing it must advance it past that whole array, rather than past its first character. The conversion of the array expression *p++ to a pointer for the call must not change the type or increment of p.
Relevant clauses of C99, as reproduced in N1256:
5: Additional checks
Compiler Explorer comparison: SDCC trunk, SDCC 4.6.0, GCC trunk and Clang trunk.
Both SDCC versions produce the incorrect one-byte increment with -mz80 --std-c99. GCC and Clang at -std=c99 -O2 compile test to return 1 after calling sink.
This was found while testing single evaluation of an array argument to the strb_t macros. The reduced example requires neither macros nor library headers. SDCC 4.6.0 also exhibits the problem, so I have not identified it as a recent regression.
Attaching a candidate bugfix created using Codex that with need to be reviewed by another developer as per the rules.