views:

169

answers:

1

I am designing a Padding struct as follows:

/* Padding. */
struct CGPadding {
 CGFloat left;
 CGFloat top;
 CGFloat right;
 CGFloat bottom;
};
typedef struct CGPadding CGPadding;

CG_INLINE CGPadding CGPaddingMake(CGFloat left, CGFloat top, CGFloat right, CGFloat bottom) { CGPadding p; p.left = left; p.top = top; p.right = right; p.bottom = bottom; return p; }

This all works perfectly well, the problem is how can I create a const CGPadding CGPaddingZero? If I do like this:

const CGPadding CGPaddingZero = (CGPadding){0.0, 0.0, 0.0, 0.0};

It doesnt work. So what am I doing wrong?

A: 

I find this very interesting because I do it all the time on the iPhone and it works fine. May it have something to do with the typedef afterward to the same name? What if you get rid of the typedef and define your struct like this?

typedef struct CGPadding {
 CGFloat left;
 CGFloat top;
 CGFloat right;
 CGFloat bottom;
} CGPadding;

Does it work then? Also, since all 0's is zero for a float as well and you're zero-ing out the whole thing, you could just say

const CGPadding CGPaddingZero = {0};

I do this stuff all the time on the iPhone so I'd be quite surprised if it doesn't work for you.

Chris
It says Duplicate symbol _CGPaddingZero in blabla.o file (...) Failed with Exit code 1
Mark