• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: BOOL array
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: BOOL array


  • Subject: Re: BOOL array
  • From: dreamcat7 <email@hidden>
  • Date: Thu, 11 Sep 2008 11:52:45 +0100

" 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 (email@hidden)

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:
This email sent to email@hidden


References: 
 >Re: BOOL array (From: Scott Ribe <email@hidden>)
 >Re: BOOL array (From: Quincey Morris <email@hidden>)

  • Prev by Date: Inter-machine notifications
  • Next by Date: Re: Cocoa application running very slow under 64 bit
  • Previous by thread: Re: BOOL array
  • Next by thread: Re: BOOL array
  • Index(es):
    • Date
    • Thread