v2 of that specification just appeared on the C comittee website:
A Common C/C++ Core Specification rev 2
For an introduction to the originial version see “A common C/C++ core specification”
Most important additions in this revision are
- three-way comparison (spaceship operator)
- “initializer” construct for captures of lambdas
- a tool for textual representation of all basic types and arrays, totext
- more attributes: core::free , core::realloc, core::noleak,
- if with variable definitions
and some more cleanups and harmonizations between C and C++.
I just published a new document on the WG14 (C committee) site
N2494: A common C/C++ core specification
It is attempt to push the fast-forward button to the annoyingly slow development process for C and its coordination with C++.
Continue reading “A common C/C++ core specification”
The recent integration of the floating point technical specifications (TS) has had a disastrous effect on the set of reserved identifiers in C. If C2x would go through as it currently stands about 1700 identifiers that were completely unprotected and unannounced would enter the global name space and nasty conflicts with user code would become unavoidable. There have been several attempts in history to introduce scoped identifiers to C, but we can’t wait for such miracles to happen before C2x is supposed to come out.
Therefore, in a paper for WG14 that will be debated in the next meeting in Ithaca, I propose to take emergency measures and rename most of these new identifiers before they hit the public. On a complementary aspect, we propose decent names for the newly introduced floating point types.
N2426 Jens Gustedt, Contain the floating point naming explosion
A new edition of the book Modern C and much more are now available under a CC license via the following page
This edition is the result of a collaboration with Manning, and improves a lot over the previous edition; material has been rewritten and reordered, a lot of graphics have been added. Manning has a nicely formatted print and eBook versions of this, there are links and information how to purchase this through the central link above, even with a limited 50% price reduction. Or a click on the cover may directly take you to Manning.
C11’s thread interface was not very clear on failure conditions that some functions might encounter. It was not clear that wait functions for conditional variables (
cnd_t) and tentative locking of mutexes (
mtx_t) may fail spuriously, that is with not apparent reason for the caller. By lack of such a specification, it was not clear how C11 threads could be realized by POSIX threads, e.g.
Allowing spurious wakeups is particularly important for the wait functions, because it makes implementing the
cnd_t type much easier, in particular for the special case that the caller of
cnd_broadcast does not hold the lock on the corresponding mutex. On the other hand, from an application point of view this does not change much. Even without spurious wakeups, a thread that called `
cnd_wait`, e.g, must in any case check the real condition they are interested in.
Continue reading “Spurious failures of thread functions”
In C11, 22.214.171.124, introduces
atomic_compare_exchange generic functions. These are precious tools when using atomics: they allow to conditionally store new data in an atomic variable and to retrieve a previous value of it, eventually. You can see that as a generalization of
atomic_fetch_and_add where we are also able to retrieve a counter value and change it at the same time.
C11 stated that the value would be taken into account for the conditional part, that is that the existing value would be compared to a desired value. This works well for arithmetic types, where value and object representation are mostly the same. It works less well if the atomic type is a structure because
struct types simply have no equality operator.
Continue reading “compare exchange compares memory and not value”
In C11, there was a problem with the fact that
atomic_flag is one of the rare types that is not considered to have a value, but it only has state (clear and set) which is changed via function calls. (
cnd_t are other examples of such types.) There was no established relation between these states and the return value of the
atomic_flag_test_and_set functions (which is
C17 clears that up by prescribing the return values of
Continue reading “C17: reformulations for atomic_flag”