Sign in

username:

password:



Not a member?

Search msp430



Search tips

Subscribe to msp430



Ads

Discussion Groups

Discussion Groups | MSP430 | Iar va_list issue

The purpose of this group is to foster exchange of information on the Texas Instruments MSP430 family of microcontrollers and related tools. Everyone welcome, all levels of familiarity/expertise.

Iar va_list issue - Bukitoo - Sep 11 15:46:00 2008

Hi!

I am programming a function in with I pass as arguent many strings and it
concateates all of them.

Basically I 've modified iar's help example (COPIED BELOW):
#include
void va_cat(char *s, ...)
{
char *t;
va_list ap;

va_start(ap, s);
while (t = va_arg(ap, char *)) null pointer ends list
{
s += strlen(s); skip to end
strcpy(s, t); and copy a string
}
va_end(ap);
}

But the null pointer assignment when the list finishes never shows up.

Why is that ? Wha Am I doing wrong ?

[Non-text portions of this message have been removed]
------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )


Re: Iar va_list issue - Anders Lindgren - Sep 12 7:51:24 2008

Bukitoo wrote:
> I am programming a function in with I pass as arguent many strings and it
> concateates all of them.
>
> Basically I 've modified iar's help example (COPIED BELOW):

Hi!

One rule of thumb is to post a complete example, in this case you should
demonstrate how you call your function...

Anyway, I tested the function and it appears to run smoothly here. The
following program prints "one two three", as expected:

#include
#include
#include
void va_cat(char *s, ...)
{
char *t;
va_list ap;

va_start(ap, s);
while (t = va_arg(ap, char *)) // null pointer ends list
{
s += strlen(s); // skip to end
strcpy(s, t); // and copy a string
}
va_end(ap);
}

#include
int main()
{
char buf[100] = "";

va_cat(buf, "one ", "two ", "three", NULL);

puts(buf);
}

-- Anders Lindgren, IAR Systems
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.

------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

RE: Iar va_list issue - Bukitoo - Sep 12 8:34:33 2008

Thanks Anders!
Yesterday I've realized that I had to pass as argument a NULL pointer at the
end. That was my missundestanding about the example.
Now I have the function working correctly.

Thanks!!!

_____

De: m...@yahoogroups.com [mailto:m...@yahoogroups.com] En nombre de Anders
Lindgren
Enviado el: viernes, 12 de septiembre de 2008 8:51
Para: m...@yahoogroups.com
Asunto: Re: [msp430] Iar va_list issue

Bukitoo wrote:
> I am programming a function in with I pass as arguent many strings and it
> concateates all of them.
>
> Basically I 've modified iar's help example (COPIED BELOW):

Hi!

One rule of thumb is to post a complete example, in this case you should
demonstrate how you call your function...

Anyway, I tested the function and it appears to run smoothly here. The
following program prints "one two three", as expected:

#include
#include
#include
void va_cat(char *s, ...)
{
char *t;
va_list ap;

va_start(ap, s);
while (t = va_arg(ap, char *)) // null pointer ends list
{
s += strlen(s); // skip to end
strcpy(s, t); // and copy a string
}
va_end(ap);
}

#include
int main()
{
char buf[100] = "";

va_cat(buf, "one ", "two ", "three", NULL);

puts(buf);
}

-- Anders Lindgren, IAR Systems
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.

[Non-text portions of this message have been removed]
------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )