• 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
struct masquerading as an array?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

struct masquerading as an array?


  • Subject: struct masquerading as an array?
  • From: email@hidden
  • Date: Fri, 11 Mar 2005 22:53:48 -0600

This is really more of a C question, but can I legitimately replace:

	id args[4];
	[array getObjects:args];
	if ([args[0] evaluate:args[1]]) ...

with:

	struct {
		id parser;
		id condition;
		id trueExpr;
		id falseExpr;
	} args;
	[array getObjects:&args];
	if ([args.parser evaluate:args.condition]) ...

The reason is that the readability of "args.condition" is better than "args[1]". Using macros or enums for the indices could accomplish the same readability goal, but the indices are context sensitive which would lead to a plethora of permutations of enums/macros.

I can't see why the C compiler would align an array of pointers differently than a struct of pointers. I do suppose I'm making the gross assumption that getObjects: is more efficient than n-many calls to objectAtIndex:. Any advice?

Daryn

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: Trying to understand "real memory" usage
  • Next by Date: Re: Is Mac Mini capable to develop cocoa app?
  • Previous by thread: Re: Startup Items
  • Next by thread: Main window not appearing after activate
  • Index(es):
    • Date
    • Thread