The C language is one of the oldest among the popular languages in use today. C is a conservative language.
The good news is that the language is aging well and it has been rejuvenated by the latest standards. The C99 and C11 standards bring many niceties…
- Fixed-length types such as uint32_t for unsigned 32-bit integers.
- A Boolean type called bool.
- Actual inline functions.
- Support for the restrict keyword.
- Builtin support for memory alignment (stdalign.h).
- Full support for unicode strings.
- Mixing variable declaration and code.
- Designated initializers (e.g., Point p = { .x = 0, .y = 0};).
- Compound literals (e.g., int y[] = (int []) {1, 2, 3, 4};).
- Multi-thread support (via threads.h).
These changes make the code more portable, easier to maintain and more readable.
The new C standards are also widely supported (clang, gcc, Intel). This year, Microsoft made it possible to use the clang compiler within Visual Studio which enables compiling C11-compliant code in Visual Studio.
Good advances every one. I don’t suspect they will be coming to the Linux Kernel any time soon – which is one of the only places where I use plain C.
Sadly no. It is a shame.
Try NetBSD 🙂
Would this work for people working on micro-controllers?
Compilers for micro-controllers might not support even the C89 standard. However, a $5 Raspberry Pi would support C99.
Mixing variables with code has always been a terrible idea / practice. Put them up front, together, so they can be found easily, so the compiler can allocate and release them in one stack frame, so you have an easier time seeing WTF you’re doing in terms of memory load, so your IDE can tell you, all in one place, what you need to clean up. Never declare a function’s variables away from the head of the function. You’re just making things harder on everyone, including yourself, and you might be causing lousy code generation as well. The lazy-making “benefit” of scattering variables all over a function is wholly illusory. 40 years of coding experience speaking here.
so the compiler can allocate and release them in one stack frame (…) and you might be causing lousy code generation as well
Any performance benefit you might perceive after declaring variables up front is, to use your own term, “wholly illusory”.
We can certainly debate maintainability and readability, but not performance.