" use NSMutableData objects with 1 byte for each 0 or 1 value. You can then get the BOOL values as 'data.bytes [index]', set them with 'data.mutableBytes [index] = someBool' and resize the array with 'data.length = someLength'. In terms of source code, that's about as minimalistic as it gets without
being pure C."


But mutableData is a void*. If we try to address it directly;

        NSMutableData* defaultOptions = [NSMutableData dataWithLength:20];
        defaultOptions.mutableBytes [03] = YES;

it gives the following compiler error

 warning: dereferencing 'void *' pointer
 error: invalid use of void expression



I believe this happens because ANSI C compiler cannot cast the LHS expression (to change the void* into a char*), and then it doesnt know how many bytes to increment to get to the [03] of the array because void type is sizeless.

From the apple examples, it shows we can make a temporary assignment and that will work; http://developer.apple.com/documentation/Cocoa/Conceptual/BinaryData/Tasks/WorkingMutableData.html#/ /apple_ref/doc/uid/20002150-133973

        NSMutableData* defaultOptions = [NSMutableData dataWithLength:20];
        signed char * foo = defaultOptions.mutableBytes;
        foo [03] = YES;

However needing the extra line for the assignment defeats the convenience.
Add a category method to NSMutableData which returns a char*  ?




_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to