srinivas reddy wrote in
news: om:
> Hi,
> I have following questions.
> 1. Does va_arg allow one to read user defined types. My compiler
> allows but I am wondering whether it is true for all.
The types have to be POD (Plain Old Data) types, a POD is basicaly
a builtin type (int etc) or struct/union that could be compiled by
a C compiler (this is an over-simplification).
> 2. I wrote the following code.
> Pardon my omitting declarations etc..
>
> int main()
> {
> func(10, "baaaaa");
> }
>
> void func(int i, ...)
> {
> va_list ap;
> va_start(ap, i);
> string* s = va_arg(ap, string*);
What's string is it std::string or is it char or char *
This is what you need here:
char const *s = va_arg(ap, char const *);
> va_end(ap);
>
> cout << (int) *s;
> }
>
> It prints 0x62616161. Why is this happening.
Unless you tell us what "string" is we have know way of knowing.
Try:
std::cout << s << std::endl;
> I mean why is it casting
> char to int and putting it in int*.
I see now such thing ?
> And also I couldn't find where the
> last two characters are stored. Could some body explain how va_arg
> actually works.
All thats important is that it does what the C++ Standard says it does.
Understand what the Standard say's you can do and do that.
How the va_arg macro works is defined by your implementation and
will vary considerably from one implementation to another.
> I know that variable length functions can be
> substituted with virtual functions and overloaded functins but I am
> curious.
>
HTH
Rob.
--
http://www.victim-prime.dsl.pipex.com/