What is the recommended way of accessing pointer structure members inside
a block function?

Consider the following code:

    obj->width = 320;
    obj->height = 240;

    dispatch_async(dispatch_get_main_queue(), ^{
        printf("WIDTH: %d HEIGHT: %d\n", obj->width, obj->height);
    });
        
    obj->width = 640;
    obj->height = 480;

I *always* want the block function to use the variable values at the
time of the *declaration* of the block function, not at the time of
its execution, i.e. obj->width and ->height should always be 320 and 240,
respectively, in the block function above.

What is the recommended way of doing this? Should I just assign them
to temporary variables whose values are never changed, e.g.

    obj->width = 320;
    obj->height = 240;

    tmpwidth = obj->width;
    tmpheight = obj->height;

    dispatch_async(dispatch_get_main_queue(), ^{
        printf("WIDTH: %d HEIGHT: %d\n", tmpwidth, tmpheight);
    });
        
    obj->width = 640;
    obj->height = 480;

Or is there a nicer solution? I'm asking because the temporary variable
solution can become quite ugly if there are many variables...

-- 
Best regards,
 Andreas Falkenhahn                          mailto:andr...@falkenhahn.com

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to