Re: C99 [was: RESTful API's - Easy way to interact?]
Re: C99 [was: RESTful API's - Easy way to interact?]
- Subject: Re: C99 [was: RESTful API's - Easy way to interact?]
- From: Jens Alfke <email@hidden>
- Date: Wed, 4 Jun 2008 18:18:35 -0700
On 4 Jun '08, at 6:06 PM, Randall Meadows wrote:
Two ways:
1) int i;
for(i=0; i<length; i+=1 )
B) Adjust the "C Language Dialect" project setting to include C99.
I'd recommend the latter. C99 is backward compatible has a lot of
useful additions to C. This topic came up recently on the xcode-users
list and I posted this plug:
The best features IMHO are:
* Conveniences that C++ has always had:
* variable declarations don't have to go at the beginning of a
block (this *really* cleans up code and eliminates a lot of
opportunities to use uninitialized variables)
* you can declare the loop variable inside a 'for' loop, i.e.
for (int x=0; x<10; x++) { ... }
* "//" comments; but I think in the real world, all C compilers
already supported those
* Variable-length local arrays. This is syntactic sugar for alloca,
and can be used to eliminate some temporary allocations. Just be
careful not to use this with arbitrarily large arrays, or you can
overflow the stack.
size_t size = strlen(str)+1;
char buf[size];
memcpy(buf,str,size);
The improvements to struct initializers are great, too.
And if that's not enough for you, you can set the compiler dialect
to "G99" and get a bunch of cool GCC-only extensions. You can read
about those in the GCC 4 documentation buried inside the developer
docs.
—Jens
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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