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: Nate Weaver <email@hidden>
- Date: Thu, 5 Jun 2008 12:55:34 -0500
FWIW, the default C dialect on OS X seems to allow a lot of C99 stuff
(I assume because it defaults to GNU extensions): variable
declarations anywhere in a block, "//" comments, and variable-length
arrays. It doesn't allow declarations in the start of a for loop,
though.
On Jun 4, 2008, at 8:18 PM, Jens Alfke wrote:
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_______________________________________________
_______________________________________________
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