The new C11 standard for the C language has some features I think are exciting.
- Threads and mutexes have been brought into the standard library
- A set of atomics and thread-local storage primitives are defined
- UTF-16 and UTF-32 to multibyte conversion functions are added
- Static compile-time assertions allow the use of sizeof() and friends
- The safer C library functions: fopen_s, strcpy_s, etc.
- Anonymous structs and unions
- Type-generic macros
- Variable length arrays, for example
For quite a while now, the basic GNU guidance on choosing languages has been to go with C or Guile first, and choose other languages only for special cases. But the basic GNU and GNOME practice in recent years has been to go with pretty much anything other than C or Guile for new code. People avoid C because it is too much manual labor, and people avoid Guile for other reasons.
If GNU wants its coders to stick with C in non-kernel space, as a community, we've got to stop discouraging the use of new features that improve the life of a C coder and the readability of C code.
The argument against using new features of C99 and now C11 is that it harms portability. However, making a virtue of requiring C89 discourages the use of these time-saving constructs, which drives coders away from C, which harms (a different type of) portability.
Variable-length arrays, alone, would save a tremendous amount of time and energy:
int func(int n)
{
double arr[n];
}
In this case, the array 'arr' is allocated and freed automatically.
All the major C compilers have committed to implementing these features: gcc, clang, and the non-free offerings. In the next few months, all the major compilers will be up to speed. Soon the only reason not to use C11 will be because you want to target older or minority compilers.
Let's make our lives just a little bit easier, and use the new features.
9 comments:
The current situation is unacceptable, compilers must implement current standards.
I agree, we should all strive support the new c11 standard.
i think you should look into ada2012.org
think missile guidance system code turned multicore conscious c++ killer
@Andreas
I work in aerospace engineering, and I got my start in the mid-90s just as original Ada was losing steam.
I always had a soft spot for idea of Ada. Because on the projects I work on now, the problems Ada was created to solve still exist.
C89 and the related TC1 attempted to mainly "codify existing practice", whereas C99 attempted language (and runtime) extension that was experimental (or even theoretical) and not based on widespread existing implementations. A considerable number of the changes in C99 seemed to be a fop to FORTRAN programmers, rather than keeping the spirit and structue of C. C11 standard neffort was a *much* better process, deliberately excluding wild-and-wacky (and unproven, ubtested) enhancements.
For new program development, I would gladly adopt C11 as a baseline, but existing code may well be better served by C89 (as extended by TC1 in 1994).
And of course, things like VLAs should probably be excluded from OS *kernel* code, as the large OS-mediated runtime assist will not be available.
"Variable-length arrays, alone, would save a tremendous amount of time and energy"
AMEN TO THAT BUDDY
YEAH BUDDY LIGHTWEIGHT BABY
One of the reasons GNOME (and primarily all the way down to GLib) use C89 is because of the Microsoft C compiler. As sad as that sounds, making sure existing software runs on Windows (things like Gobject, Gtk, Pidgin) is important.
Once all of the target platforms support C99 (or in this case C11), then glib and related libraries would need to be updated. (Use uint instead of guint for example).
It is a lot of non-trivial work, but I agree that it would be worth it (once those compilers have caught up).
Christian-
I didn't know that Glib compiled with native MSVC. That's interesting.
I've heard that Microsoft is pushing for full support of C++11 in the near term, which might get us most of the practical parts of C99 as a by-product.
Until C/C++ is headerless (i.e. only one source file), it's an irritation. Waiting for import/export becoming a standard lol.
Post a Comment