All chapters of the C23 edition of Modern C now available in early access
Jens Gustedt's Blog
by Jens Gustedt
2M ago
At the same time as WG14 (the C committee) voted C23, now all 21 sections of the new edition are available via Manning’s early access program on Modern C, Third Edition — Covers the C23 standard This new edition broadly covers all the novelties that will come with C23, many of them make coding in C easier and more reliable. It’s worth a look. Major public domain compilers such as gcc and clang are getting ready to support most of this in their next releases, so you on many platforms you will be able to use these new features right away. Some pieces are still missing though, namely some of the ..read more
Visit website
White space does matter in C23
Jens Gustedt's Blog
by Jens Gustedt
3M ago
Usually in C identifiers are not directly followed by strings. But when U prefixed literals were introduced in C. there still were some rare clashes with existing code. This happened were a macro U that expanded to a string was used to add some sort of leading character sequence to a string. Prior, this usage was not sensible to whether or not there was a space between the two. By introducing the prefix the two usages (with and without space) became distinct and code changed its meaning or became invalid. So for this situation, space is in fact already significant. Generally, it is often assum ..read more
Visit website
The deprecated attribute in C23 does much more than marking obsolescence
Jens Gustedt's Blog
by Jens Gustedt
3M ago
You may already have heard that C23 proposes a new syntax feature called attributes and that one of the standard attributes in C23 is called deprecated. Actually, we got this whole attribute thing and also some of the standard attributes from C++, where they had been introduced in C++11 (I think). One of the uses of this particular attribute is to mark a given feature as obsolescent. For example in C23 we now have [[deprecated]] char* asctime(const struct tm* timeptr); [[deprecated]] char* ctime(const time_t* timer); This simply says that user code should not use these functions anymore, an ..read more
Visit website
Early access to the C23 edition of Modern C
Jens Gustedt's Blog
by Jens Gustedt
3M ago
Manning’s early access program (MEAP) for the new edition is now open at https://www.manning.com/books/modern-c-third-edition There is a special code mlgustedt2 to get 45% off of the official price. This is currently limited until Jan 2, 2024, but will most likely be extended for some weeks. The previous edition already has been largely successful and is considered by some as one of the reference books on C. This new edition has been the occasion to overhaul the presentation in many places, but its main purpose is the update to the new C standard, C23. The goal is to publish this new editi ..read more
Visit website
The fediverse is watching
Jens Gustedt's Blog
by Jens Gustedt
6M ago
WordPress now offers a direct link with the fediverse. So if you have e.g a mastodon account, you can now follow my blog directly from there ..read more
Visit website
The new __VA_OPT__ feature in C23
Jens Gustedt's Blog
by Jens Gustedt
9M ago
C23 brings a new macro feature that eases programming with variadic macros a lot. Before it has been a challenge to detect if a ... argument was actually empty or contained at least one real token. This feature was introduced into C23 by a paper by Thomas Köppe “Comma omission and comma deletion” A similar feature had already been integrated to C++20 before. As an example for the feature, suppose we want to augment calls to fprintf such that two types of problems are detected: If there is only a format argument and no others, we want to use fputs to avoid scanning the format at execution t ..read more
Visit website
Enforced bounds checking for frozen function interfaces
Jens Gustedt's Blog
by Jens Gustedt
11M ago
Many function interfaces in the C library and other legacy codes have interfaces that don’t permit the current bounds checking syntax for array parameters, but that are frozen in time such that nobody will ever be able to change and improve them. In this example we go with void* memcpy(void*restrict s1, void const*restrict s2, size_t n); but in fact any existing interface that has size parameters after array or pointer parameters that depend on them has similar problems. The intent of this post is to show how the corresponding header can be easily tuned, such that modern compilers are able ..read more
Visit website
Dealing with overflow
Jens Gustedt's Blog
by Jens Gustedt
1y ago
In the previous post we have seen that C23 will provide us with tools for efficient overflow check for arithmetic. When discussing this, several people have asked why these tools do not provide a specific model to handle overflow, such as aborting or raising a signal. The answer to this is actually quite simple: There is no commonly agreed strategy to handle overflow. So for the C committee (and for the gcc feature this is based upon) there was no obvious choice for a strategy. Instead, the features provide the basics to implement any such strategy based on policy decisions that will be depend ..read more
Visit website
C23 implications for C libraries
Jens Gustedt's Blog
by Jens Gustedt
1y ago
The upcoming standard C23 has a lot of additions to the C library clause. Most of them are small, some of them are big but optional. I have now finished a first version of a document that summarizes many of the changes. It has some general discussions about the following subjects Unicode support Thread safety of the C library Const-contract of the C library Changes to integer types Attributes and then lists changes to individual header files of the C library. This does not contain an detailed description of the changes to the math.h header. First, I am really not an expert on that, and secon ..read more
Visit website
A defer feature using lambda expressions
Jens Gustedt's Blog
by Jens Gustedt
2y ago
In the previous post https://gustedt.wordpress.com/2020/12/14/a-defer-mechanism-for-c/ I already presented an idea for a defer feature for C, namely a feature that would provide a simple mechanism to cleanup at the end of a block, regardless how that block is left. There are many different extension out there that provide such a feature, for example POSIX’ pthread_cleanup_push and pthread_cleanup_pop, Microsoft’s __try and __finally and gcc’s cleanup attribute. Although they are used quite often, none of these extension has yet been adopted widely enough to prefer it over the others for standa ..read more
Visit website

Follow Jens Gustedt's Blog on FeedSpot

Continue with Google
Continue with Apple
OR