Re: Cocoa and C99
Re: Cocoa and C99
- Subject: Re: Cocoa and C99
- From: Patrick Mau <email@hidden>
- Date: Mon, 6 Oct 2008 10:23:54 +0200
Hi Gerrit
You could use explicit basic blocks:
static void loop(void)
{
int i = 5;
float f = 10.0;
this();
and_that();
/* new badic block */
{
int i;
float f = 1.0;
for (i = 0; i < 5; i++) {
printf("%d %g\n", i, f);
f += 2.0;
}
}
i++; /* 6 */
f += 1.0; /* 11.0 */
}
To improve readability and flow-control for 'break'-like constructs, I
sometimes use:
static void a_func(void)
{
do {
if (cond())
break;
if (other_cond())
break;
result = call_me();
} while (0);
}
The line you tried declares two variables of type 'int',
therefore the warning:
for( int i = 0, f = 0.0; i < 3; i++, f += 3.5 ) { printf("%g",f); };
A small remark about personal taste. I try to avoid all constructs I
pointed
out, even 'for (int i = 0; ....) {}'.
The 'do { ... } while (0);' is useful in preprocessor macros.
Regards,
Patrick
On 06.10.2008, at 09: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?
Tiger 10.4.11; gcc version 4.0.1 (Apple Computer, Inc. build 5363)
Kind regards,
Gerriet.
_______________________________________________
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>) |