posibilities of 'RETURN'

Discussion in 'C++' started by noe, May 25, 2004.

  1. noe

    noe Guest

    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.
     
    noe, May 25, 2004
    #1
    1. Advertising

  2. noe

    Leor Zolman Guest

    On Tue, 25 May 2004 12:22:52 -0400, "noe" <> 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
     
    Leor Zolman, May 25, 2004
    #2
    1. Advertising

  3. noe

    Gregg Guest

    "noe" <> wrote in
    news::

    > 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
     
    Gregg, May 26, 2004
    #3
  4. noe

    Andre Heinen Guest

    On Tue, 25 May 2004 12:22:52 -0400, "noe" <>
    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"
     
    Andre Heinen, May 26, 2004
    #4
  5. noe

    red floyd Guest

    Andre Heinen <> wrote in message news:<>...
    >[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 :).
     
    red floyd, May 26, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. PvdK
    Replies:
    0
    Views:
    2,981
  2. wl
    Replies:
    2
    Views:
    585
    Dimitri Maziuk
    Mar 5, 2004
  3. Ganesh Gella
    Replies:
    4
    Views:
    362
    Stuart Gerchick
    Nov 12, 2004
  4. Seong-Kook Shin
    Replies:
    1
    Views:
    493
    Richard Bos
    Jun 18, 2004
  5. Greenhorn
    Replies:
    15
    Views:
    827
    Keith Thompson
    Mar 6, 2005
Loading...

Share This Page