linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Wolfgang Denk <wd@denx.de>
To: rabeeh@galileo.co.il
Cc: linuxppc-embedded@lists.linuxppc.org
Subject: Re: problems with powerpc-linux-gcc
Date: Wed, 13 Dec 2000 16:26:36 +0100	[thread overview]
Message-ID: <200012131526.eBDFQaT21707@denx.local.net> (raw)
In-Reply-To: Your message of "Wed, 13 Dec 2000 16:23:55 +0200." <3A37867B.2070606@galileo.co.il>


In message <3A37867B.2070606@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@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/

  reply	other threads:[~2000-12-13 15:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-12-13 14:23 problems with powerpc-linux-gcc Rabeeh Khoury
2000-12-13 15:26 ` Wolfgang Denk [this message]
2000-12-14  6:16 ` PCMCIA have machine check Nguyen Xuan Hoang
2000-12-13 17:15   ` clark
2000-12-13 17:36   ` mlocke
2000-12-13 17:37   ` mlocke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200012131526.eBDFQaT21707@denx.local.net \
    --to=wd@denx.de \
    --cc=linuxppc-embedded@lists.linuxppc.org \
    --cc=rabeeh@galileo.co.il \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).