functions question

S

Sonoman

Hi all:
I have to functions. Function A that returns a parameter and function B that
takes a parameter, both are the same type. Can I put a call to function A as
a parameter for function B? or is it better to put the returned value from A
into a variable and the put that variable into B as a parameter? Which is a
better programming practice? Thanks in advance
 
B

Buster

Sonoman said:
Hi all:
I have to functions. Function A that returns a parameter and function B that
takes a parameter, both are the same type. Can I put a call to function A as
a parameter for function B? or is it better to put the returned value from A
into a variable and the put that variable into B as a parameter? Which is a
better programming practice? Thanks in advance

Generally speaking it's fine to pass the return value of one function as an
argument to a second function. There are sometimes issues with exception
safety if the value is a pointer to a dynamically allocated object, especially
if
the second function takes more than one such argument.

Can you be more specific about the problem you are trying to solve?

Regards,
Buster.
 
J

jeffc

Buster said:
Generally speaking it's fine to pass the return value of one function as an
argument to a second function.

I think he meant the function as expression.
void f(int);
int g();

// call
f(g());

If that's what he meant, then I think the call I wrote is fine, as long as
it's maintainable. If it gets longer and difficult to understand, it should
be changed. If it is too hard to debug (you want to see the value of g()
before f gets called), it should be changed.
 
B

Buster

I think he meant the function as expression.
void f(int);
int g();

// call
f(g());

I think that's what I meant too. What do you think I meant? :)
If that's what he meant, then I think the call I wrote is fine, as long as
it's maintainable. If it gets longer and difficult to understand, it should
be changed. If it is too hard to debug (you want to see the value of g()
before f gets called), it should be changed.

I think you're right. OTOH it might just about be possible to come
up with an example where it's unsafe. The person who writes is
very good at coming up with those examples.

Later,
Buster.
 
B

Buster

Buster said:
I think you're right. OTOH it might just about be possible to come
up with an example where it's unsafe. The person who writes

Dammit. Does anyone ever use overwrite mode on purpose?
The person who writes GOTW ...
 
J

jeffc

Buster said:
I think that's what I meant too. What do you think I meant? :)

When you wrote "it's fine to pass the return value of one function as an
argument to a second function", I thought you meant
int i = g();
f(i);

This sounds like the conversation between the 2 German guards in the No One
Lives Forever computer game (you had to be there :)
 
B

Buster

jeffc said:
When you wrote "it's fine to pass the return value of one function as an
argument to a second function", I thought you meant
int i = g();
f(i);

Ahh. Yes, I see that I didn't say what I meant. Thanks.
This sounds like the conversation between the 2 German guards in the No One
Lives Forever computer game (you had to be there :)

OK.

Regards,
Buster.
 
K

Kevin Goodsell

Buster said:
Dammit. Does anyone ever use overwrite mode on purpose?

I turn it on all the time, but never on purpose. I don't think I ever
use that key intentionally, but it's right next to 3 keys I use
constantly. I often think about just prying that sucker off my keyboard.
A less permanent solution would be nice... I wonder if there's an
application available for disabling particular keys...

-Kevin
 
M

Mike Wahler

Kevin Goodsell said:
I turn it on all the time, but never on purpose. I don't think I ever
use that key intentionally, but it's right next to 3 keys I use
constantly. I often think about just prying that sucker off my keyboard.
A less permanent solution would be nice... I wonder if there's an
application available for disabling particular keys...

I'm not sure about 'disable', but there are applications
which allow the assignment of given functions to particular
keys. Perhaps assign the 'insert' key to a 'beep' operation,
or perhaps to play an audio file which says "fumble-fingers!"
:)

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top