On 20010723 Guillaume Cottenceau wrote:
>
>> People progamming in C should know how much of C++ features are 'backported' to
>> C99.
>
>I would be interested to know more on that backport stuff you're talking
>about. Do you have a link?
>
C99 is really a secure and powerfull addition. Some of this features are already
present in some way in actual gcc or other C compilers, but C99 standarises them.
This is what I find more usefull, extracted from
http://gcc.gnu.org/gcc-3.0/c99status.html:
- restricted pointers that can not be null nor serve to walk arrays. Someone
can think this is stupid, but how many times did you a ptr++ that pointed
to a standalone struct ? It also can help to generate better code
(http://www.lysator.liu.se/c/restrict.html)
- mix of code and declarations: thay are no more forced to be at the beginning
of a block (this also implies changes in the calling conventions, stack for
local variables is not reserved and initialized at once, but for each variable or
group of contiguous variables).
- This helps for loop and data locality (block scopes):
for (int i=0; ...)
case (char c=getchar())
{
}
- the above also makes possible non-constant length arrays (forget 50% of your
mallocs and allocas):
int a = 2;
double b[a];
double c[argc];
and variable length arrays in params with checks
void f(int a, int h[a]) // instead of int h[] or int* h
{
for (int i=0; i<a; i++)
printf("%d\n",h[i]);
}
- remove implicit int return value
- designated initializers
struct complex { double a,b } = { b:7, a:3 ];
- inline functions (yes, gcc already supports this...)
- *good* vargarg macros, even with empty args
I know many people will find all this superfluous, but I see many of the features
in C++ (some of the above are not C++), that have made some of my code rewrites
10 times faster (ie, 10 times less debugging) in C++ than plain C.
--
J.A. Magallon # Let the source be with you...
mailto:[EMAIL PROTECTED]
Mandrake Linux release 8.1 (Cooker) for i586
Linux werewolf 2.4.7 #1 SMP Mon Jul 23 01:55:36 CEST 2001 i686