• 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: "Flattened" Compound literals
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "Flattened" Compound literals


  • Subject: Re: "Flattened" Compound literals
  • From: Jean-Denis MUYS <email@hidden>
  • Date: Thu, 29 Mar 2012 15:22:51 +0000
  • Thread-topic: "Flattened" Compound literals

Duh! Interesting.

I had tried it with an iOS project. So I just created a new Foundation project with very simple code inserted in the "main" template:

	NSRect r = {0,1,2,3};
	NSLog(@"r = %@", NSStringFromRect(r);
	r = (NSRect){4,5,6,7};
	NSLog(@"r = %@", NSStringFromRect(r);

It compiles and runs just fine on my Mac and on a coworker's Mac too. Both running Xcode 4.3.2.

On my terminal "clang --version" reports:

	Apple clang version 3.1 (tags/Apple/clang-318.0.58) (based on LLVM 3.1svn)

Which might or might not be the same compiler as I also have Xcode 4.4DP2 installed.

If this is all the same on your Mac, then yes, I'd be interested in comparing compiler switches.

Jean-Denis



On 29 mars 2012, at 17:02, Eeyore wrote:

> I'm getting complaints (with clang) if I try either
>
> myRect = {0,0,10,10};
>
> or
>
> myRect = (CGRect){0,0,10,10}
>
> so my guess is that it is some compiler switch. If you want a full list of my configuration settings, I would be happy to send it to you so you can compare to determine which setting is the important one.
>
> Aaron
>
>
> On Mar 29, 2012, at 7:52 AM, Jean-Denis MUYS wrote:
>
>> I have been using C compound literals for quite some time. I prefer them to the old-style calls to CGRectMake and CGPointMake for example:
>>
>>   CGPoint myPoint = { 10, 20};
>> 	[…]
>>   myPoint = (CGPoint){20, 40};
>>
>>
>>   myRect = (CGRect){ myPoint, {400, 200}};
>>
>> And so on. But I just found out by accident that the compiler accepts the following just fine:
>>
>>   myRect = (CGRect){ 20, 40, 400, 200};
>>
>> Instead of the more conform:
>>
>>   myRect = (CGRect){{20, 40}, {400, 200}};
>>
>> So the compiler lets the programmer "flatten" the struct in her compound literals.
>> Is this supported by the C99 standard or is this some clang extension? (assuming both forms behave the same).
>>
>> Jean-Denis
>>
>>
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Xcode-users mailing list      (email@hidden)
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>


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

This email sent to email@hidden


  • Follow-Ups:
    • Re: "Flattened" Compound literals
      • From: Eeyore <email@hidden>
References: 
 >"Flattened" Compound literals (From: Jean-Denis MUYS <email@hidden>)
 >Re: "Flattened" Compound literals (From: Eeyore <email@hidden>)

  • Prev by Date: Re: "Flattened" Compound literals
  • Next by Date: Re: "Flattened" Compound literals
  • Previous by thread: Re: "Flattened" Compound literals
  • Next by thread: Re: "Flattened" Compound literals
  • Index(es):
    • Date
    • Thread