We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I added a putchar routine to my main program ... a call to my new putchar works as expected but a call to printf acts like it is still using the old putchar what am I missing here?
I created the following simple program:
#include <stdio.h> char putchar (char c) { return (c); } void main (void) { printf (""); while (1) { } }
INPUT MODULES INCLUDED: .\STARTUP.obj (?C_STARTUP) main.obj (MAIN) C:\KEIL\C51\LIB\C51S.LIB (PRINTF) C:\KEIL\C51\LIB\C51S.LIB (?C?CLDPTR) C:\KEIL\C51\LIB\C51S.LIB (?C?CLDOPTR) C:\KEIL\C51\LIB\C51S.LIB (?C?CSTPTR) C:\KEIL\C51\LIB\C51S.LIB (?C?PLDIIDATA) C:\KEIL\C51\LIB\C51S.LIB (?C?CCASE)
#include <stdio.h> void main (void) { printf (""); while (1) { } }
INPUT MODULES INCLUDED: .\STARTUP.obj (?C_STARTUP) main.obj (MAIN) C:\KEIL\C51\LIB\C51S.LIB (PRINTF) C:\KEIL\C51\LIB\C51S.LIB (?C?CLDPTR) C:\KEIL\C51\LIB\C51S.LIB (?C?CLDOPTR) C:\KEIL\C51\LIB\C51S.LIB (?C?CSTPTR) C:\KEIL\C51\LIB\C51S.LIB (?C?PLDIIDATA) C:\KEIL\C51\LIB\C51S.LIB (?C?CCASE) C:\KEIL\C51\LIB\C51S.LIB (PUTCHAR)
I tried the XREF and looked at the linker output .... putchar is NOT on the list of included functions printf does seem ref my _putchar function so it looks like printf should use my putchar function ... this is what made me think it was not using my putchar ... I added this test code to my program
putchar ( '>'); printf ( "AB"); putchar ('>');
does printf "hold" its output til it's got a \n ?
Nope. The printf function does not buffer the output. Jon
If it had a buffer, It would be such a big problem in an Embedded. printf is also non-reentrant ( no buffer )...