Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > posibilities of 'RETURN'

Reply
Thread Tools

posibilities of 'RETURN'

 
 
noe
Guest
Posts: n/a
 
      05-25-2004
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.


 
Reply With Quote
 
 
 
 
Leor Zolman
Guest
Posts: n/a
 
      05-25-2004
On Tue, 25 May 2004 12:22:52 -0400, "noe" <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Gregg
Guest
Posts: n/a
 
      05-26-2004
"noe" <(E-Mail Removed)> wrote in
news:(E-Mail Removed) 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
 
Reply With Quote
 
Andre Heinen
Guest
Posts: n/a
 
      05-26-2004
On Tue, 25 May 2004 12:22:52 -0400, "noe" <(E-Mail Removed)>
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"
 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      05-26-2004
Andre Heinen <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>. ..
>[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 .
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments