Domanda

At the bottom of CGGeometry.h the following function and macro definitions are declared:

CG_INLINE bool
__CGPointEqualToPoint(CGPoint point1, CGPoint point2)
{
  return point1.x == point2.x && point1.y == point2.y;
}
#define CGPointEqualToPoint __CGPointEqualToPoint

CG_INLINE bool
__CGSizeEqualToSize(CGSize size1, CGSize size2)
{
  return size1.width == size2.width && size1.height == size2.height;
}
#define CGSizeEqualToSize __CGSizeEqualToSize

My question, just out of curiosity, is why declare the CGPointEqualToPoint and CGSizeEqualToSize macros? Why not just use the inline function definitions, like all the CG...Make functions declared right above them? Like so:

CG_INLINE CGPoint
CGPointMake(CGFloat x, CGFloat y)
{
  CGPoint p; p.x = x; p.y = y; return p;
}

CG_INLINE CGSize
CGSizeMake(CGFloat width, CGFloat height)
{
  CGSize size; size.width = width; size.height = height; return size;
}
È stato utile?

Soluzione

An older version of CoreGraphics used to declare the symbols as

extern int CGPointEqualToPoint(CGRect rect1, CGRect rect2);
extern int CGSizeEqualToSize(CGRect rect1, CGRect rect2);

As CoreGraphics evolved, someone decided the implementation of those methods was trivially inlinable, something which was either not thought of, or not acted upon when CoreGraphics was first written. Simply deprecating the old non-inline version could have introduced a binary incompatibility (an aggressive-enough inliner not even bothering to emit the symbol coupled with an old app looking for that symbol would have blown up). The defines are just patches over the old identifier so all you see are the new definitions, not the old symbols.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top