By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,115 Members | 894 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,115 IT Pros & Developers. It's quick & easy.

write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter

P: n/a
hi all
basically my problem is i have to write a function such that when ever
i call this function in some other function .it should give me tha data
type and value of calling function parameter.and no of parameter is
calling function can be anything.
for example.suppose my function is function2.
then when i call
function1(int i ,char j,float d)
{
function2()
}

ouput should be
i is integer
j is char
d is float

and data type can be anything

Jul 23 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
On 24 Jan 2005 20:47:35 -0800, "komal" <av*************@gmail.com>
wrote:
hi all
basically my problem is i have to write a function such that when ever
i call this function in some other function .it should give me tha data
type and value of calling function parameter.and no of parameter is
calling function can be anything.
for example.suppose my function is function2.
then when i call
function1(int i ,char j,float d)
{
function2()
}

ouput should be
i is integer
j is char
d is float

and data type can be anything


I question the wisdom or usefulness of doing this. Sounds like a
homework assignment to me.

Anyway, you can try using the ellipsis and va_arg, but there are
certain restrictions as to the types of arguments you can pass. Most
importantly, the standard says that invoking va_arg on non-POD class
types results in undefined behavior (section 5.2.2 part 7). To use
va_arg, you need to include <cstdarg>.

Also, check out the std::type_info class for non-POD class RTTI.
Include the header <typeinfo> to use this class.

--
Bob Hairgrove
No**********@Home.com
Jul 23 '05 #2

P: n/a

komal wrote:
hi all
basically my problem is i have to write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter.and no of parameter is
calling function can be anything.
for example.suppose my function is function2.
then when i call
function1(int i ,char j,float d)
{
function2()
}

ouput should be
i is integer
j is char
d is float


Impossible. function2 doesn't get any information about function1.
At the very least, you should write it as

f1(int i ,char j,float d) { f2( &f1 ); }

In that case, f2 can be a template. With Template Argument Deduction
you can then at least know the types. Still, the variable names are
only for the compiler and not available at runtime.
Regards,
Michiel Salters

Jul 23 '05 #3

P: n/a

komal wrote:
hi all
basically my problem is i have to write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter.and no of parameter is
calling function can be anything.
for example.suppose my function is function2.
then when i call
function1(int i ,char j,float d)
{
function2()
}

ouput should be
i is integer
j is char
d is float


Impossible. function2 doesn't get any information about function1.
At the very least, you should write it as

f1(int i ,char j,float d) { f2( &f1 ); }

In that case, f2 can be a template. With Template Argument Deduction
you can then at least know the types. Still, the variable names are
only for the compiler and not available at runtime.
Regards,
Michiel Salters

Jul 23 '05 #4

P: n/a
Bob Hairgrove wrote:

On 24 Jan 2005 20:47:35 -0800, "komal" <av*************@gmail.com>
wrote:
hi all
basically my problem is i have to write a function such that when ever
i call this function in some other function .it should give me tha data
type and value of calling function parameter.and no of parameter is
calling function can be anything.
for example.suppose my function is function2.
then when i call
function1(int i ,char j,float d)
{
function2()
}

ouput should be
i is integer
j is char
d is float

and data type can be anything


I question the wisdom or usefulness of doing this. Sounds like a
homework assignment to me.

Anyway, you can try using the ellipsis and va_arg, but there are
certain restrictions as to the types of arguments you can pass. Most
importantly, the standard says that invoking va_arg on non-POD class
types results in undefined behavior (section 5.2.2 part 7). To use
va_arg, you need to include <cstdarg>.


And it wouldn't help anyway.
When working with va_arg you already need to know the type of the
passed arguments. That's one reason why printf has those fancy %d, %f
&c, %s, ... formatting flags.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 23 '05 #5

P: n/a

komal wrote:
hi all
basically my problem is i have to write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter.and no of parameter is
calling function can be anything.
for example.suppose my function is function2.
then when i call
function1(int i ,char j,float d)
{
function2()
}

ouput should be
i is integer
j is char
d is float


Impossible. function2 doesn't get any information about function1.
At the very least, you should write it as

f1(int i ,char j,float d) { f2( &f1 ); }

In that case, f2 can be a template. With Template Argument Deduction
you can then at least know the types. Still, the variable names are
only for the compiler and not available at runtime.
Regards,
Michiel Salters

Jul 23 '05 #6

P: n/a

komal wrote:
hi all
basically my problem is i have to write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter.and no of parameter is
calling function can be anything.
for example.suppose my function is function2.
then when i call
function1(int i ,char j,float d)
{
function2()
}

ouput should be
i is integer
j is char
d is float


Impossible. function2 doesn't get any information about function1.
At the very least, you should write it as

f1(int i ,char j,float d) { f2( &f1, i,j,d ); }

In that case, f2 can be a template. With Template Argument Deduction
you can then at least know the types. Still, the variable names are
only for the compiler and not available at runtime.
Regards,
Michiel Salters

Jul 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.