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?
Try again without the putchar()-prototype in stdio.h. Make sure that your own putchar()-function is public. HHK
stdio.h shouldn't matter - the compiler doesn't care where the prototype appears, so long as it's there somewhere; and the Linker knows nothing about prototypes. Just make sure that the prototype really does agree with the definition. As HHK said, make sure it's Public (else the Linker won't see it) Note that C51 names functions differently depending on whether they pass parameters in registers, or are reentrant. Have you set some inappropriate options here?
I tried to remove the putchar prototype in stdio.h and put one in my main source file ... it didn't seem to help ... I think the function is public ... my putchar is called _putchar in the symbol table with the words PUBLIC CODE PROC the code for my putchar routine is in my main source file ... the prototype for the putchar is in the stdio.h ... it uses the pragma regparms my function matches the prototype in stdio.h ... char putchar ( char ) I use the "favor small code" option .... I have not made any attempt to make the routine reentrant... I appreciate the responses to my request for help ... I hope the information above points to a solution
Did you use all lower-case letters for your function (please check!) ? The "_"-character preceding the function name is added by the compiler to indicate that the function passes parameter(s) in register(s). You must not use this character as first character of your function. Have you tried to link the program using IXREF-control for the linker ? The map file should show where your function is used. If your putchar is called by printf and defined in main, then the cross reference listing should show both file names as reference for putchar. HHK
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 )...