472,952 Members | 2,203 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,952 software developers and data experts.

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

Jul 23 '05 #1
6 1921
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

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

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

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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers...
9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
11
by: JKop | last post by:
Take the following simple function: unsigned long Plus5Percent(unsigned long input) { return ( input + input / 20 ); } Do yous ever consider the possibly more efficent:
3
by: Webdiyer | last post by:
I want to integrate SecurID two-factor authentication system of the RSASecurity.inc into our asp.net application,but I get into trouble when trying to call the API functions of the ACE Agent,I got...
40
by: Neo The One | last post by:
I think C# is forcing us to write more code by enforcing a rule that can be summarized as 'A local variable must be assgined *explicitly* before reading its value.' If you are interested in what...
9
by: Alan Silver | last post by:
Hello, I'm a bit surprised at the amount of boilerplate code required to do standard data access in .NET and was looking for a way to improve matters. In Classic ASP, I used to have a common...
14
by: Mr Newbie | last post by:
I am often in the situation where I want to act on the result of a function, but a simple boolean is not enough. For example, I may have a function called isAuthorised ( User, Action ) as ?????...
16
by: hzmonte | last post by:
Correct me if I am wrong, declaring formal parameters of functions as const, if they should not be/is not changed, has 2 benefits; 1. It tells the program that calls this function that the...
5
by: StephQ | last post by:
This is from a thread that I posted on another forum some days ago. I didn't get any response, so I'm proposing it in this ng in hope of better luck :) The standard explanation is that pointer...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.