Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   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 (http://www.velocityreviews.com/forums/t288400-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.html)

komal 01-25-2005 04:47 AM

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
 
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


Bob Hairgrove 01-25-2005 08:57 AM

Re: 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
 
On 24 Jan 2005 20:47:35 -0800, "komal" <avinash.gangwal@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
NoSpamPlease@Home.com

msalters 01-25-2005 10:27 AM

Re: 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
 

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


msalters 01-25-2005 11:03 AM

Re: 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
 

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


Karl Heinz Buchegger 01-25-2005 11:04 AM

Re: write a function such that when ever i call this function in someother function .it should give me tha data type and value of callingfunction parameter
 
Bob Hairgrove wrote:
>
> On 24 Jan 2005 20:47:35 -0800, "komal" <avinash.gangwal@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
kbuchegg@gascad.at

msalters 01-25-2005 11:13 AM

Re: 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
 

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


msalters 01-25-2005 11:13 AM

Re: 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
 

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



All times are GMT. The time now is 08:13 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.