need help in pointers
SPI_SPI (char* p1, char* p2)
{
return ( *(point*)p1 == *(point*)p2 ) ? '0' : 'F'; // epsilon
}
is this show that p1 caste to point class pointer and give pointer to this pointer point class.. am i r开发者_开发问答ight? i am not getting pointer in every case plz refer me a usefull link related to it... or explain me this .
That function compares two points using comparison specified for point
object by casting point structures referenced through char*
pointers.
That code equals to:
// casting char* to point*
point* ptPointer1 = (point*)p1;
point* ptPointer2 = (point*)p2;
// extracting values
point pt1 = *ptPointer1;
point pt2 = *ptPointer2;
// comparing by value
return pt1 == pt2 ? '0' : 'F';
Original code:
SPI_SPI (char* p1, char* p2)
{
return ( *(point*)p1 == *(point*)p2 ) ? '0' : 'F'; // epsilon
}
As an ordinary function this definition lacks a result type, and is invalid code. As a constructor it attempts to return a value, and is invalid code. So either way it's invalid code.
Regarding your question, I fail to parse it: it seems to be nonsense.
Cheers & hth.,
You are comparing the value pointed by p1 (cast to a point class) to the value pointed by p2 (also cast to point class). If they are equal, you return '0' else you return 'F'. Your function doesn't have a return value, unless this is included in SPI_SPI, which would make it a macro. This kind of macro use is strongly unrecommended (by me atleast). Also, it is usually best to capitalise classes (Point).
精彩评论