Linux MIPS Architecture development
 help / color / mirror / Atom feed
From: David Daney <ddaney@caviumnetworks.com>
To: "wilbur.chan" <wilbur512@gmail.com>
Cc: Linux MIPS Mailing List <linux-mips@linux-mips.org>
Subject: Re: va_list implementation on mips64 , with 32bit cross compiled
Date: Wed, 13 Oct 2010 17:15:00 -0700	[thread overview]
Message-ID: <4CB64B84.2030402@caviumnetworks.com> (raw)
In-Reply-To: <AANLkTinJXcpd7rVj4QFY0CpskSiZuJB4y10sbG1Td5n9@mail.gmail.com>

On 10/13/2010 05:06 PM, wilbur.chan wrote:
> I am planning  to use va_list on a single module, however the
> following code did not work properly.
>
> typedef char *	va_list;
> #define _INTSIZEOF(n)	( (sizeof(n) + sizeof(int) - 1)&  ~(sizeof(int) - 1) )
> #define va_start(ap,v)	( ap = (va_list)&v + _INTSIZEOF(v) )
> #define va_arg(ap,t)	( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
> #define va_end(ap)	( ap = (va_list)0 )
>

You cannot arbitrarily define those macros with garbage and expect 
anything to work.

Replace all the above code with #include <stdarg.h>

Then do: man stdarg

That documents how it works.

David Daney


> void test_val_list()
> {
> unsigned long test=0x1234;
> test_printk("test:0x%x OK\n",aaa);
> }
>
> void test_printk(const char *format, ...)
> {
> va_list args;
> va_start(args, format);
> unsigned int v1 = va_arg(args,unsigned long);
> printk("v1 is 0x%x\n",v1);
> unsigned int v2 = va_arg(args,unsigned long);
> printk("v2 is 0x%x\n",v2);
> }
>
>
> The result is :
>
> v1 is 0x00000013
>
> v2 is 0x00000019
>
> Why this happened ? shouldn't v1 be 0x1234 here?
>
> Thank you
>
>

      reply	other threads:[~2010-10-14  0:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-14  0:06 va_list implementation on mips64 , with 32bit cross compiled wilbur.chan
2010-10-14  0:15 ` David Daney [this message]

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=4CB64B84.2030402@caviumnetworks.com \
    --to=ddaney@caviumnetworks.com \
    --cc=linux-mips@linux-mips.org \
    --cc=wilbur512@gmail.com \
    /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