• 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: Cocoa and C99
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa and C99


  • Subject: Re: Cocoa and C99
  • From: "Clark Cox" <email@hidden>
  • Date: Mon, 6 Oct 2008 01:04:09 -0700

On Mon, Oct 6, 2008 at 1:00 AM, Andrew Farmer <email@hidden> wrote:
> On 06 Oct 08, at 00:49, Gerriet M. Denkmann wrote:
>>
>> In the old days I wrote:
>>
>> int i; float f;
>> for( i = 0, f = 0.0; i < 5; i++, f+= 3.5 ) .....
>>
>> Now I am trying to use the C99 style:
>> for( int i = 0, float f = 0.0; i < 5; i++, f+= 3.5 ) .....
>> But I am told: "parse error before 'float'".
>>
>> Then I tried:
>> float f;
>> for( int i = 0, f = 0.0; i < 3; i++, f += 3.5 ) { printf("%g",f); };
>> But got: format '%g' expects type 'double', but argument 2 has type 'int'
>> and: unused variable 'f'
>>
>> So: how to declare two variables of different type which are to be valid
>> only in a for-loop?
>
> You can't. The C99 spec only allows you to make a single variable
> declaration in a loop. If you need to declare multiple variables, do that
> outside the loop.

FYI: You *can* declare multiple variables in the for loop, but they
all have to be the same type:

for(int i = 0, j = 10; i < j; ++i) {
}

--
Clark S. Cox III
email@hidden
_______________________________________________

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: 
 >Cocoa and C99 (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: Cocoa and C99 (From: Andrew Farmer <email@hidden>)

  • Prev by Date: Re: Cocoa and C99
  • Next by Date: Re: window controllers and managed object contexts
  • Previous by thread: Re: Cocoa and C99
  • Next by thread: Re: Cocoa and C99
  • Index(es):
    • Date
    • Thread