• 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: Initializing Structures
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Initializing Structures


  • Subject: Re: Initializing Structures
  • From: Kyle Sluder <email@hidden>
  • Date: Wed, 05 Nov 2014 16:27:29 -0600

On Wed, Nov 5, 2014, at 04:11 PM, Greg Parker wrote:
> The C language allows a struct variable to be initialized in its
> declaration using the brace syntax, but does not allow that form to be
> used anywhere else.
>
> C99 adds this syntax ("compound literal") that works anywhere:
>
>     NSView *view = [[NSView alloc]
>     initWithFrame:(NSRect){{0,0},{80,20}}];
>

The compound literal syntax is also a lot more flexible: it can
initialize members by name; they can be initialized out of order;
members in nested structs can be initialized directly; and all members
that are not initialized explicitly are initialized to zero.

What I'm saying is, it's really handy and you should look it up.

--Kyle Sluder
_______________________________________________

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: 
 >Initializing Structures (From: Richard Charles <email@hidden>)
 >Re: Initializing Structures (From: Greg Parker <email@hidden>)

  • Prev by Date: Re: Initializing Structures
  • Next by Date: Re: NSImage glowing
  • Previous by thread: Re: Initializing Structures
  • Next by thread: auto layout exception: Unable to create description in descriptionForLayoutAttribute_layoutItem_coefficient. Something is nil
  • Index(es):
    • Date
    • Thread