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

posibilities of 'RETURN'

P: n/a
noe
Hello, I'm writing a file system filter driver and I've found in an example
this sentence:

if (VALID_FAST_IO_DISPATCH_HANDLER( fastIoDispatch, FastIoRead )) {

return (fastIoDispatch->FastIoRead)(
FileObject,
FileOffset,
Length,
Wait,
LockKey,
Buffer,
IoStatus,
nextDeviceObject );
}
--------------------------------
I've never seen this type of 'return'. What is it doing here? Why does it
have so much parameters? Can it be a routine?

Thanks in advance.
Jul 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Tue, 25 May 2004 12:22:52 -0400, "noe" <no*****@mixmail.com> wrote:
Hello, I'm writing a file system filter driver and I've found in an example
this sentence:

if (VALID_FAST_IO_DISPATCH_HANDLER( fastIoDispatch, FastIoRead )) {

return (fastIoDispatch->FastIoRead)(
FileObject,
FileOffset,
Length,
Wait,
LockKey,
Buffer,
IoStatus,
nextDeviceObject );
}
--------------------------------
I've never seen this type of 'return'. What is it doing here? Why does it
have so much parameters? Can it be a routine?
It is a call through either a pointer-to-function or a function object,
depending on how FastIoRead is defined.

Here's a trivial example using a pointer-to-function:

#include <iostream>
using std::cout;
using std::endl;

double crunch();

double sum(double a, double b)
{
return a + b;
}

int main()
{
cout << crunch() << endl;
return 0;
}

double crunch()
{
typedef double (*func_t)(double, double);
func_t fp = sum;

return (fp)(2.2, 3.3);
// return fp(2.2, 3.3);
// return (*fp)(2.2, 3.3);
}
Note that any of the three return statements shown do exactly the same
thing. The language provides some leeway on how to write a call through a
pointer-to-function.
-leor

Thanks in advance.


--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #2

P: n/a
"noe" <no*****@mixmail.com> wrote in
news:6c******************************@localhost.ta lkaboutprogramming.com:
Hello, I'm writing a file system filter driver and I've found in an
example this sentence:

if (VALID_FAST_IO_DISPATCH_HANDLER( fastIoDispatch, FastIoRead )) {

return (fastIoDispatch->FastIoRead)(
FileObject,
FileOffset,
Length,
Wait,
LockKey,
Buffer,
IoStatus,
nextDeviceObject );
}
--------------------------------
I've never seen this type of 'return'. What is it doing here? Why does
it have so much parameters? Can it be a routine?

Thanks in advance.


The parameters are not parameters to "return", they are parameters to the
function pointed to by fastIoDispatch->FastIoRead. It would be equivalent
to

result = (fastIoDispatch->FastIoRead)(
FileObject,
FileOffset,
Length,
Wait,
LockKey,
Buffer,
IoStatus,
nextDeviceObject);

return result;

where result is of an appropriate type. Maybe you are not aware that
return does not require parentheses around its argument, and as a result
did not know how to mentally parse this return statement.

Gregg
Jul 22 '05 #3

P: n/a
On Tue, 25 May 2004 12:22:52 -0400, "noe" <no*****@mixmail.com>
wrote:
return (fastIoDispatch->FastIoRead)(
FileObject,
<snip>
nextDeviceObject );
I've never seen this type of 'return'. What is it doing here? Why does it
have so much parameters?
There is only one type of return, and it takes only one
parameter. The return you see here is the usual one, and takes
only one parameter, namely
(fastIoDispatch-> ... nextDeviceObject )

If I guess right:
fastIoDispatch->FastIoRead is a member function,
(fastIoDispatch->FastIoRead) is the same with redundant (),
(fastIoDispatch->FastIoRead)(FileObject, ... ) is a call to that
function. The call will yield *one* value, which will be
returned.

If the redundant () bother you, remove them:
fastIoDispatch->FastIoRead(FileObject, ... )
Can it be a routine?


No, because "return" is a reserved name.

--
Andre Heinen
My address is "a dot heinen at europeanlink dot com"
Jul 22 '05 #4

P: n/a
Andre Heinen <no****@nospam.invalid> wrote in message news:<02********************************@4ax.com>. ..
[redacted]
fastIoDispatch->FastIoRead is a member function,
(fastIoDispatch->FastIoRead) is the same with redundant (),
(fastIoDispatch->FastIoRead)(FileObject, ... ) is a call to that


You're close. This is Win32 DDK code. It's pure C, not C++.
fastIoDispatch->FastIoRead is a structure member that is a pointer to
function taking (whatever) as a parameter, returning (most likely)
DWORD.

However, I've gone completely off topic and should be shot :-).
Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.