Jens Gustedt's Blog

April 17, 2018


Filed under: C11, C17, defects — Jens Gustedt @ 08:48

C17 is a “bugfix release” of the C standard. Whereas the intention of the C working group (WG14) has been that this release does not introduce normative changes (but one), it brings a lot of clarifications all over the place. By adopting this version, some features as implemented by some compilers may change if their interpretation of C11 was different because of an unfortunate ambiguity. The schedule for C17 is as follows:

  • Nov. 2017, adoption by WG14, subject to some minor, editorial changes
  • Dec. 2017, integration of these changes and approval by an editorial committee
  • Jan. to Mar. 2018, editorial back and forth with ISO, more editorial changes due to new requirements by ISO and their strict enforcement
  • Apr 2018, ISO sends out the FDIS (final draft international standard) to the national bodies.
  • Apr to June 2018, ballot (ongoing)
  • June or July 2018, publication (tentative)

I identified the following list of changes in C17 compared to C11. The whole process of clarifications that have been integrated is transparently documented in what we called “defect reports”. So if you urgently need to know about some of these you should look them up, there.

My intention is to write a post on most of the items to explain my POV of what happened.  In particular, I will try to cite the new versions of the changed text for reference. Because of copyright issues, I will only be able to do that once C17 has been published by ISO. So please be patient and stay tuned.

    • atomics: initialization (7.17.2, 7.31.8), coherence requirements (, fences (7.17.3 p11), functions or macros (7.17.1 p6), lockfree depends on type (7.17.5 p3), compare exchange compares memory and not value (, atomic_flag (7.17.18)
    • threads: spurious wakeup ( p2, p2, p3), synchronization (7.26.4 p1), thread specific storage (tss_t) and thread exit (7.26.5 p3,, 7.26.6)
    • _Generic (
    • rvalues and qualification, cast (6.5.4)
    • alignment: fundamental alignment (6.2.8), _Alignas (6.7.5), aligned_alloc (
    • sequence points: full expressions (6.8 p4), full declarators (6.7..6 p3)
    • infinite loops (6.8.5 p6)
    • reserved identifiers (7.1.3)
    • domain or range errors (7.12.1), ilogb, erfc, lgamma,
    • underspecification of clock (
    • underspecification of realloc for size 0 (
    • Annex F: FLT_ROUNDS (F.2 p1)
    • Annex K: tmpnam_s, snprintf_s, sprintf_s, vsprintf_s, get_s, mbstowcs_s, wcstombs_s, snwprintf_s, swprintf_s, vsnwprintf_s, vswprint_s, mbsrtowcs_s, wcsrtombs_s

NB: comments are switched off for this post. Please communicate errors or imprecisions that you spotted to me directly. If on the other hand you want to discuss the future (or not) of C, there are a lot of places out there. The best that I know of is WG14 itself. So if you really care, please sign in on your committee of your national standards body for programming languages of alike, and invest yourself in the process.


July 29, 2016

Improving the specification of arithmetic for atomics

Filed under: C11, defects, library — Jens Gustedt @ 12:08

In a document to the standards committee of last year I had observed a set of unfortunate inconsistencies in C11’s specification of arithmetic operations for atomics. As you perhaps know such operations can be specified with operators a++ (in the language part) or generic functions atomic_fetch_add(&a, 1) (in the library), but unfortunately the two parts had not been redacted to fit well in all places.

My new document Minimal Suggested Corrigendum for Arithmetic on Atomic Objects will hopefully make it as proposed corrigendum into the next “bugfix” version of the standard, and hopefully this new version will see the light and the end of 2017. It will perhaps not be with the exact words as they are presented, but I think that the text already comes close to what the intent of the committee had been, and to what implementors actually do, anyhow.

May 11, 2015

The controlling expression of _Generic

Filed under: C11, defects, language — Jens Gustedt @ 22:06

Recently it showed that the C standard seems to be ambiguous on how to interpret the controlling expression of _Generic, the one that determines the choice. Compiler implementors have given different answers to this question; we will see below that there is code that is interpreted quite differently by different existing compilers. None of them is “wrong” at a first view, so this tells us that we must be careful when we use _Generic. In this post I will try to explain the problem and to give you some work around for common cases.


October 24, 2012

C11 defects: initialization of padding

Filed under: C11, C99, defects, language — Jens Gustedt @ 21:55

The C11 has added an attempt to force compilers to initialize padding of structures and unions under certain circumstances. Unfortunately the situation has become confusing now, since it still foresees that padding can be treated differently from other parts of structures that are not initialized explicitly.


October 14, 2012

C11 defects: C threads are not realizable with POSIX threads

Filed under: C11, defects, language, POSIX — Tags: — Jens Gustedt @ 21:19

This post is mainly identical to a defect report that hopefully will be discussed by the C standards committee on their next meeting. I found that problem that this raises needs to be better known before people start using this interface more widely, so I decided to also publish it here.

The thread interfaces as they are declared in the threads.h header are largely underspecified, such that interpreting them is often just guess-work and leaves room for a wide range of interpretations. This is particularly irritating since there already is an ISO standard about threads that is quite elaborated and mature, namely ISO/IEC 9945:2009, commonly know as POSIX 2010. C11 mentions ISO/IEC 9945:2009, but completely misses to technically relate to it on the thread interface. The semantic specification of C11 threads is in parts so loose, that a stringent implementation of C11 threads on top of POSIX doesn’t seem possible.

Other platforms that are less formalized than POSIX have their own technical restrictions that should additionally be taken into account. The “other platform” for threads that clearly had been targeted by the committee are threads on Microsoft Windows platforms. Most other widely used commodity operating systems are POSIX compatible (from mainframes down to Android phones). But we should not underestimate the potential of the C threads interface. Because it has a reduced interface it might be suitable for a larger range of platforms than we can foresee today. Because C threads don’t enforce a complete share of the address space, such platforms could e.g be accelerators (providing a portable thread interface on GPU?) or networks on chips. The only memory that must be shared by C threads are objects with static storage duration and objects allocated through malloc and friends. Thus freestanding environments without malloc would only be required to shared statically allocated objects.

In the following I only give an incomplete list of the defects as I noticed them, I suspect that there might be a lot of others.


April 17, 2012

C11 defects: underspecification of tss_t

Filed under: C11, defects, language — Jens Gustedt @ 15:32

Section 7.26.6 “Thread-specific storage functions” of C11 is severely underspecified since it uses terms that are not introduced (so far) in the context of C. This is really a pity, since POSIX also has pthread_key_t that is completely feature equivalent and for which the specification is much more complete.

Jacob Navia had observed that at several occasions in comp.std.c but it seems that he had not got enough attention such that this had made it in a defect report.


March 21, 2012

C11 defects: initialization of atomic_flag

Filed under: C11, defects, language — Jens Gustedt @ 16:44

With this post I will be starting some random collection of things that I consider being defects of the C11 standard. Perhaps someone of the committee could pick them up or send me a mail to discuss them and eventually formulate a formal defect report.

C11 expresses the intention to have atomic_flag as a primitive that should allow to emulate all other atomic types and operations, 7.17.8 p3 in a note says:

The remaining types can be emulated with atomic_flag, though with less than ideal properties.


Create a free website or blog at