The new C standards are worth it

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.

Published by

Daniel Lemire

A computer science professor at the University of Quebec (TELUQ).

7 thoughts on “The new C standards are worth it”

  1. 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.

    1. 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.

Leave a Reply

Your email address will not be published.

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

You may subscribe to this blog by email.