posibilities of 'RETURN'

N

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 );
}
 
L

Leor Zolman

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 );
}

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
 
G

Gregg

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
 
A

Andre Heinen

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

red floyd

Andre Heinen said:
[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 :).
 

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

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top