Unable to understand the code fragement

Discussion in 'C++' started by shan_rish@yahoo.com, Aug 24, 2005.

  1. Guest

    Hi Group,

    I am not able to understand the following code fragement (a return
    statement of a function). bsearch is a binary search function and the
    (CompareFunction)RnDtsComparitor) parameter is the one which i dont
    understand. Any help is appreciated.


    //typedefed in a seperate file
    typedef int (*CompareFunction)(const void*,const void*);

    //Doubt fragement
    return (RnDts*) bsearch(&key,
    TrffDt.RnDtsDt,
    TrffDt.cnt[RNDTCNT],
    sizeof(RnDts),
    (CompareFunction)RnDtsComparitor);

    I dont know if any other information is needed. If needed i will post
    the needed information also.
    Cheers
    Shan
     
    , Aug 24, 2005
    #1
    1. Advertising

  2. Srini Guest

    > Hi Group,
    >
    > I am not able to understand the following code fragement (a return
    > statement of a function). bsearch is a binary search function and the
    > (CompareFunction)RnDtsComparit­or) parameter is the one which i dont
    > understand. Any help is appreciated.


    It is a pointer to a function that would be used by 'bsearch' to
    compare 2 values while doing the sort. Provision to provide a
    comparison function through a function pointer is what makes it
    possible to sort different types of data.

    Srini
     
    Srini, Aug 24, 2005
    #2
    1. Advertising

  3. Guest

    Thanks...
    Cheers
    Shan

    Srini wrote:
    > > Hi Group,
    > >
    > > I am not able to understand the following code fragement (a return
    > > statement of a function). bsearch is a binary search function and the
    > > (CompareFunction)RnDtsComparit­or) parameter is the one which i dont
    > > understand. Any help is appreciated.

    >
    > It is a pointer to a function that would be used by 'bsearch' to
    > compare 2 values while doing the sort. Provision to provide a
    > comparison function through a function pointer is what makes it
    > possible to sort different types of data.
    >
    > Srini
     
    , Aug 24, 2005
    #3
  4. Guest

    Srini wrote:
    > > Hi Group,
    > >
    > > I am not able to understand the following code fragement (a return
    > > statement of a function). bsearch is a binary search function and the
    > > (CompareFunction)RnDtsComparit­or) parameter is the one which i dont
    > > understand. Any help is appreciated.

    >
    > It is a pointer to a function that would be used by 'bsearch' to
    > compare 2 values while doing the sort. Provision to provide a
    > comparison function through a function pointer is what makes it
    > possible to sort different types of data.
    >
    > Srini


    Thanks...
    Cheers
    Shan
     
    , Aug 24, 2005
    #4
    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. Nitin Goyal
    Replies:
    3
    Views:
    725
  2. neo
    Replies:
    4
    Views:
    330
  3. Sanchit

    unable to understand this typedef

    Sanchit, Mar 20, 2008, in forum: C Programming
    Replies:
    1
    Views:
    273
    Eric Sosman
    Mar 20, 2008
  4. Paul Liebrand
    Replies:
    0
    Views:
    279
    Paul Liebrand
    Feb 9, 2004
  5. Jake Barnes
    Replies:
    6
    Views:
    442
    9.co.uk
    Feb 8, 2006
Loading...

Share This Page