This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

printf problem

putchar works but printf does not ... my putchar is used by printf
so the problem must be in my code somewhere??

I started deleting sections of code until my printf
started to work ... then I narrowed it down to
a single statement ... statement in - it worked,
statement out - printf didn't work ... the
statement was in a routine that did not get
executed .. deleting other statements made
printf work ... the program was only 5161
bytes when I reached to go/no go condition

Have you ever heard of anything like this???

Any ideas on how to find out what is going on??

Parents
  • I assume you are using Keil's printf in the library. We (I) would probably need to see your putchar to see how it is written. Does your putchar follow the ansi standard for its arguments?

    In your example though with printing the variable vs. printing a constant, I think one would be in data space somewhere (xdata or idata), while the constant string 'AB' would be stored in code space... purhaps this is the problem? I do agree we the other response of overlays being an issue. Such a powerful feature can also create endless headaches.

Reply
  • I assume you are using Keil's printf in the library. We (I) would probably need to see your putchar to see how it is written. Does your putchar follow the ansi standard for its arguments?

    In your example though with printing the variable vs. printing a constant, I think one would be in data space somewhere (xdata or idata), while the constant string 'AB' would be stored in code space... purhaps this is the problem? I do agree we the other response of overlays being an issue. Such a powerful feature can also create endless headaches.

Children
  • How would the string constant being stored in code space
    be a problem? The printf routine gets passed the starting
    address of the string and something that tells it the address
    is code space. Nothing should be able to overlay the code
    space.

    I have narrowed the problem down to the starting address of
    the string pool. If the start address is 1FFE printf works. If the
    starting address is 2001 printf does not work. Not working means
    that printf acts like it is printing nulls.

    The putchar routine is exactly like the sample given for
    interrupt driven serial i/o.

    I am stumped. I guess my next move is to start trying to trace
    through the printf function.

  • How would the string constant being stored in code space
    be a problem? The printf routine gets passed the starting
    address of the string and something that tells it the address
    is code space.


    In theory this is true, but from experience I've seen incorrectly written/compiled code that will try to use a MOVX to fetch from code space... what you get is obviously garbage.

    It was just a shot in the dark