Wondering how printf("") might cause problems, I looked at the executed code in printf_large. Basically it should just do a read from the pointer, see that we are at the end of the string and return.
So I found the read from a pointer is the problem. Placing a read from a generic pointer in main() causes the same issues as the call to printf() (as long a printf() is linked into the binary). The attached example code printf "Hello " again and again, but never "World!". Philipp
#include <stdio.h> __sfr __at(0xe1) XBR0; __sfr __at(0xe2) XBR1; __sfr __at(0xa4) P0MDOUT; __sfr __at(0xd9) PCA0MD; __sfr __at(0x88) TCON; __sfr __at(0x89) TMOD; __sfr __at(0x8b) TL1; __sfr __at(0x8d) TH1; __sfr __at(0x98) SCON0; __sfr __at(0x99) SBUF0; __sfr __at(0xef) SRTSRC; int putchar(int c) { while(!(SCON0 & 0x02)); SCON0 &= ~0x02; SBUF0 = c; return (c); } unsigned char _sdcc_external_startup(void) { PCA0MD = 0; // Disable watchdog timer return 0; // perform normal initialization } char c; char *gptr; void main(void) { unsigned long int i = 0; // Initialize I/O pins P0MDOUT = 0x10; // Set port P0.4 (Uart tx) to push-pull XBR0 = 0x01; // UART0 on P0.4 and P0.5 XBR1 = 0x40; // Enable push/pull for Tx // Configure UART for 1200 baud, 8 data bits, 1 stop bit. TMOD = 0x20; TH1 = 150; TCON |= 0x40; SCON0 = 0x42; for(;;) { putchar('H'); putchar('e'); putchar('l'); putchar('l'); putchar('o'); putchar(' '); for(i = 0; i < 50000; i++); // Sleep c = 'W'; gptr = &c; putchar(*gptr); for(i = 0; i < 50000; i++); // Sleep putchar('o'); putchar('r'); putchar('l'); putchar('d'); printf("!"); for(;;); } }
------------------------------------------------------------------------------
_______________________________________________ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user