Re: Xcode now defaults to use C99 - so what's C99?
Re: Xcode now defaults to use C99 - so what's C99?
- Subject: Re: Xcode now defaults to use C99 - so what's C99?
- From: Jens Alfke <email@hidden>
- Date: Fri, 30 May 2008 14:07:27 -0700
C99 is very cool; it has many useful features, so don't be put off by
the idea of huge specs. Those articles look pretty useful if you
haven't already been using C99.
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
_______________________________________________
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