You shouldn't need to use "void ptr + offset to field",
you can cast the void * to be a pointer to whatever
structure you need:

        int myCompareFunc(void *p1, void *p2) // I'm leaving off the
                                                          // arguments that
*I* still
                                                          // need clarified!
        {
                myStruct *pd1 = (myStruct *) p1;
                myStruct *pd2 = (myStruct *) p2;

                if (pd1->interesting_field < pd2->interesting_field)
                        return -1;
        ...


Of course, if the elements you are comparing are
amenable to mathematical operations, you can do
something like this:

        return (int) (pd1->interesting_field - pd2->interesting_field);

This is, of course, assuming that the comparison
only requires <0, 0 or >0 return values.  If it
really needs -1, 0, 1 then you need to do the
explicit comparisons & returns.

-- 
-Richard M. Hartman
[EMAIL PROTECTED]

186,000 mi./sec ... not just a good idea, it's the LAW!


> -----Original Message-----
> From: Michael S. Davis [mailto:[EMAIL PROTECTED]]
> Sent: Monday, March 22, 1999 2:29 PM
> To: '[EMAIL PROTECTED]'
> Subject: RE: Using DmQuickSort ??
> 
> 
> 
> Ok, almost got it.  Let's say my compare functions performs
> as follows:
> 
> double elem1  // variables within a record
> double elem2  // variables within a record
> 
> if(elem1 <  elem2){ return -1 };
> if(elem1 == elem2){ return  0 };
> if(elem1 >  elem2){ return +1 };
> 
> Now my problem is this.  this is easy if I declare elem1 and elem2
> but how do I refer to these as part of the record.  I know I can get
> a pointer to the data within the record but am not sure how to make
> the comparrison without moving the data.  I'd prefer to just refer
> to these doubles, while in DB Record.
> 
> Assume fixed length record (all strings same length).
> Record:
> |<--string2-->|<-double1->|<-double2->|<-string2->| just as an example
> ^
> |____ pointer to record data: UInt dataPtr;
> 
> Can I just reference these like: 
> 
> if( *(dataPtr+OffsetToDouble1) < *(dataPtr+OffsetToDouble2) )
> {
>     return -1;
> }
> 
> Can I do something like this?  I think you get my drift.  If not
> what is the correct way to compare two doubles within a 
> Record, without
> copying them to another location.
> 
> Thanks
> 
> 
> ----------------------------------------------------
> Shoot-to-Win
> 
> Protect the 2nd Amendment
> ----------------------------------------------------
> 
> 

Reply via email to