On 1/28/2014 7:01 PM, Bint wrote:
> Hello, I have a struct, which includes another struct, like this:
>
> typedef float CGFloat;
>
> struct CGPoint {
> CGFloat x;
> CGFloat y;
> };
>
> struct LinePoint {
> CGPoint pos;
> float width;
> };
>
>
> Now, if I have a pointer to a bunch of LinePoints, can I directly assign one
> of them with another LinePoint?
>
> LinePoint P;
> LinePoint *array;
>
> *(array+i) = P;
Is there anything between those lines or are those it? I'm asking
because declaring 'array' a pointer to LinePoint and not assigning any
value to it (and not initializing it with anything valid) does not
certainly mean that you *have a pointer to _a bunch_ of LinePoints.
In fact it does not at all point to any LinePoint whatever, generally
speaking. It has a random value.
> Will it copy all of the fields, or not?
Yes, *if* 'array' points to the first valid object of type LinePoint and
there are at least 'i' of those in a row. If 'i' is such that you run
beyond the boundary of the array you have, the copying will not work
very well.
Post the code that shows how you make 'array' point to "a bunch of"
objects, and how you calculate 'i' before using the expression.
> Sometimes it seems like it does, and
> other times no. I can't figure out what is going on.
Distill your code to the bare minimum that seems to misbehave (or does
misbehave), then post it here entirely. For more information please see
section 5 of the FAQ Lite.
V
--
I do not respond to top-posted replies, please don't ask