我正在用 C 语言编写并使用 GCC 进行编译。
有没有更好的方法来声明积分。我很惊讶地看到点是一个数组。是否有某种声明点的方法,所以它看起来更像一个数组。
typedef struct Span
{
unsigned long lo;
unsigned long hi;
} Span;
typedef struct Series
{
unsigned long *points;
unsigned long count;
unsigned long limit;
} Series;
void SetSpanSeries(Series *self, const Span *src)
{
unsigned long *points;
if (src->lo < src->hi )
{
// Overlays second item in series.
points = self->points; // a pointer in self structure
points[0] = src->lo;
points[1] = src->hi;
self->count = 1;
}
}
现在让我们说点指向一个数组结构。
typedef struct Span
{
unsigned long lo;
unsigned long hi;
} Span;
span *points[4];
现在我该如何编写这些代码行?我做对了吗?
points = self->points; // a pointer in self structure
points[0].lo = src->lo;
points[0].hi = src->hi;