Menu

#2571 static initialisation for an array of pointers to functions

open
nobody
None
PIC16
5
2016-12-09
2016-12-09
M.Hoehle
No

The sdcc compiler produces wrong initialisation values for an array of pointers to functions

The example code:

/*
Fr. 09.12.2016 Bug documentation sdcc-3.6.0

compiled with: 'sdcc -mpic16 --use-non-free bug.c -c'

sdcc -v:
SDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8 3.6.0 #9615 (Linux)

the asm output shows a wrong initialisation table for the 'serbef' array!

/
extern void vxx();
extern char
cxx();
static void lecho(const unsigned char *p)
{
p=p;
}

char xlecho(const unsigned char p)
{
p=p;
return (char*)0;
}

const struct xx{
void ( * fp)();
char (fp2) ();
} serbef[]={ +-------------+
{vxx,cxx} | [ Saving ] |
, {lecho,cxx} / lecho is a valid value! / | bug.c |
, {vxx,xlecho} / xlecho is a valid value! / +-------------+
, {vxx,vxx} / at least an error message woud be fine /
, {cxx,vxx} / a warning for wrong type may be ok! /
};

void ch(void)
{
/ this dosen't work: /
(*serbef[1].fp)();
}

The (wrong) result in the asm file:

....
; ; Starting pCode block for Ival
code
_serbef:
DB LOW(_vxx), HIGH(_vxx), UPPER(_vxx), LOW(_cxx), HIGH(_cxx), UPPER(_cxx), 0x00, LOW(_cxx), HIGH(_cxx), UPPER(_cxx), LOW(_vxx), HIGH(_vxx)
DB UPPER(_vxx), 0x00, LOW(_vxx), HIGH(_vxx), UPPER(_vxx), 0x00, 0x00, 0x00

...

The tabel is too short, pointers are missing

Discussion


Log in to post a comment.

Monday.com Logo