problems with powerpc-linux-gcc 
    Wolfgang Denk 
    wd at denx.de
       
    Thu Dec 14 02:26:36 EST 2000
    
    
  
In message <3A37867B.2070606 at galileo.co.il> you wrote:
>
> I'm having trouble with compiling some code that I will use for our
> embedded system when booting the system.
This is an old story: buggy code does not work.  I  always  have  the
same problem ;-)
> The function that I'm having trouble with is the printf function. I used
To  be  more  specific:  you  have  problems  with   _your_   (buggy)
_implementation_  of  the said function. It works fine for many, many
people.
> In the powerpc environemnt (using GNU powerpc-linux-gcc cross compiler),
> the compiler puts the arguments in registers instead of the stack ; due
Right. Which is a Good Thing (TM) to do.
> static char *do_printf(char *buf, const char *fmt, const int *dp)
> {
> ...
> }
>
>
> void printf(const char *fmt, ...)
Please note that a conforming implementation of printf() returns "int".
> {
>    char buf[256],*p;
>    p = buf;
>    do_printf(buf, fmt, ((const int *)&fmt)+1);
>    while (*p) putchar(*p++);
> }
This code is WRONG!
You MUST do something like that:
#include <stdarg.h>
...
... do_printf(..., const char *fmt, va_list args)
int printf(const char *fmt, ...)
{
	va_list args;
	va_start(args, fmt);
	... do_printf(..., fmt, args);
	va_end(args);
	return (number_of_printed_chars);
}
... and RTFM: man stdarg(3)
Wolfgang Denk
--
Software Engineering:  Embedded and Realtime Systems,  Embedded Linux
Phone: (+49)-8142-4596-87  Fax: (+49)-8142-4596-88  Email: wd at denx.de
"You ain't experienced..." "Well, nor are you." "That's true. But the
point is ... the point is ... the point is we've been not experienced
for a lot longer than you. We've got  a  lot  of  experience  of  not
having any experience."           - Terry Pratchett, _Witches Abroad_
** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/
    
    
More information about the Linuxppc-embedded
mailing list