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++.
Are you new to blogging, and do you want step-by-step guidance on how to publish and grow your blog? Learn more about our new Blogging for Beginners course and get 50% off through December 10th.
WordPress.com is excited to announce our newest offering: a course just for beginning bloggers where you’ll learn everything you need to know about blogging from the most trusted experts in the industry. We have helped millions of blogs get up and running, we know what works, and we want you to to know everything we know. This course provides all the fundamental skills and inspiration you need to get your blog started, an interactive community forum, and content updated annually.
This is a new paper that appeared today on the site of the C committee:
C already has a variaty of interfaces for type-generic programming, but lacks a systematic approach that provides type safety, strong ecapsulation and general usability. This paper is a summary paper for a series that provides improvements through
- N2632. type inference for variable definitions (auto feature) and function return
- N2633. function literals and value closures
- N2634. type-generic lambdas (with auto parameters)
- N2635. lvalue closures (pseudo-references for captures)
The aim is to have a complete set of features that allows to easily specify and reuse type-generic code that can equally be used by applications or by library implementors. All this by remaining faithful to C’s efficient approach of static types and automatic (stack) allocation of local variables, by avoiding superfluous indirections and object aliasing, and by forcing no changes to existing ABI.
An overview of a paper that presents a reference implementation of a
defer mechanism (co-authored with Robert C. Seacord) has been accepted for publication at SAC’21. The full version is available as a research report on the HAL archive:
It introduces the implementation-side of a C language mechanism for error handling and deferred cleanup adapted from similar features in the Go programming language. Here is a simple example that uses such a feature:
void * const p = malloc(25);
if (!p) break;
void * const q = malloc(25);
if (!q) break;
if (mtx_lock(&mut)==thrd_error) break;
// all resources acquired
// use p, q, and mut until the end of the block
This mechanism improves the proximity, visibility, maintainability, robustness, and security of cleanup and error handling over existing language features. The library implementation of the features described by this paper is publicly available under an Open Source License at https://gustedt.gitlabpages.inria.fr/defer/.
This feature is under consideration for inclusion in the C Standard and has already been discussed on the last WG14 meeting. The main introduction can be found in a paper written together with Alex Gilding, Tom Scogland, Robert C. Seacord, Martin Uecker, and Freek Wiedijk:
A new research report describing shnell has now appeared on HAL:
We show how locally replaceable code snippets can be used to easily specify and prototype compiler and language enhancements for the C language that work by local source-to-source transformation. A toolbox implements the feature and provides many directives that can be used for compile time configuration and tuning, code unrolling, compile time expression evaluation and program modularization. The tool is also easily extensible by simple filters that can be programmed with any suitable text processing framework.
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, 188.8.131.52, 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”