opensesame icon indicating copy to clipboard operation
opensesame copied to clipboard

SDCC version > 3.6.0 error 91: extern definition for 'putchar' mismatches with declaration

Open ghost opened this issue 3 years ago • 4 comments

When you want to compile the source without error, with a version of SDCC > 3.6.0, you need to change the putchar() function prototype to fit SDCC, bacause it was changed. I tested it on SDCC v4.0 (Linux Fedora 33).

In display.h

#ifndef LOCAL
//void putchar(char c);
int putchar(int c);
#endif

and in display.c

/* sdcc provides printf if we provide this */
//void putchar(char c)
int putchar(int c)
{
 ....
 return(c);
}

ghost avatar Dec 05 '20 14:12 ghost

Thanks - do you know the exact version it needs to be adjusted or have a link with further info on the version with the change? Adjusting that fails to compile on sdcc 3.4.0 so would like some ifdefs to support both.

samyk avatar Dec 05 '20 19:12 samyk

The change of putchar() prototype was made in version 3.7.0

SDCC 3.7.0 Feature List:

  • Changed putchar() prototype from void putchar(char) to int putchar(int) to improve standard-compliance and allow error reporting.

It was a fix of an issue from 2016-06-16 (SDCC changelog):

  • Make putchar() prototype standard-compliant, fix bug #2505.

ghost avatar Dec 05 '20 20:12 ghost

Cool, it will now check version of sdcc to decide what to do. Hopefully that resolves it!

samyk avatar Dec 05 '20 23:12 samyk

I'm not sure that actually fixed it at least not for me under Windows/Linux with SDCC 4.0.0 I will start by saying I don't know wtf I'm doing but.... Shouldn't #if (SDCC_VERSION_HI == 3 && SDCC_VERSION_LO >= 7) || (SDCC_VERSION_HI >= 4) be #if (__SDCC_VERSION_MAGOR == 3 && __SDCC_VERSION_MINOR >= 7) || (__SDCC_VERSION_MAJOR >= 4)

also both in display C and H, the declaration and use of putchar() needs to be fixed for >3.7. With the code above the Int/Int that is expected turns to int/char with the current code. Adding PUTCHAR_TYPE2 fixes that. But I'm not a fan of that name.

display.h

// sdcc 3.7.0+ uses int putchar
#if (__SDCC_VERSION_MAGOR == 3 && __SDCC_VERSION_MINOR >= 7) || (__SDCC_VERSION_MAJOR >= 4)
  #define PUTCHAR_INT
  #define PUTCHAR_TYPE int
  #define PUTCHAR_TYPE2 int
#else
  #define PUTCHAR_TYPE void
  #define PUTCHAR_TYPE2 char
#endif

display.h

#ifndef LOCAL
	PUTCHAR_TYPE putchar(PUTCHAR_TYPE2 c);
#endif

display.c

/* sdcc provides printf if we provide this */
PUTCHAR_TYPE putchar(PUTCHAR_TYPE2 c)
{
#ifdef SIMULATOR
	while (!TI); /*  wait end of last transmission */
	TI = 0;
	SBUF = c; /*  transmit to serial */
#else
	u8 i;
	c &= 0x7f;
	if (c >= FONT_OFFSET)
	{
		for (i = 0; i < FONT_WIDTH; i++)
			txData(font[c - FONT_OFFSET][i] ^ (reverseTxt ? 0xff : 0));
		txData(reverseTxt ? 0xff : 0x00);
	}
#endif
#ifdef PUTCHAR_INT
  return c;
#endif
}

Ivan275g4 avatar Jan 26 '21 07:01 Ivan275g4