Jens Gustedt's Blog
878 FOLLOWERS
A blog on C programming by Jens Gustedt. Read the articles to find useful knowledge.
Jens Gustedt's Blog
2w ago
… is now available for free download from https://hal.inria.fr/hal-02383654 ..read more
Jens Gustedt's Blog
1M ago
I already talked about a proposal for an extension of the C language calleddefer, that is prospected to either be published in a technicalspecification or the next revision, C2Y, of the C standard: EĿlipsis now implements a simple form of this feature by mixing some specific preprocessor extensions (in particular counters) with the usual macro ..read more
Jens Gustedt's Blog
5M ago
EĿlipsis is an extension and continuation of the C preprocessor with the
aim to be useful for other technical languages, be they programming
languages or text processing languages.
There were several goals when developing eĿlipsis:
Provide a complete specification of a preprocessor that is, as a specification, independent from the C or C++ specifications. This will be provided in a separate document, for which this code here serves as a reference implementation.
Properly extend the preprocessor for other languages such that it can take special syntactic properties of these languages into acc ..read more
Jens Gustedt's Blog
5M ago
Recursive inclusion is possible in C, and more surprisingly it even makes sense in some cases. In fact it provides an easy way to do code unrolling of small code snippets:
#if !defined(DO_I) || (DO_I < DO_BOUND)
# include "do-incr.c"
DO_BODY
# include __FILE__
#endif
#undef DO_I
Here this uses two macros that have to be defined beforehand, DO_BOUND and DO_BODY, and one macro DO_I for a hexadecimal loop counter that is maintained by the include file "do-incr.c". If we hold the above recursive code in some file "doit.c" (plus some extras, see below) we can use this as simply as in
#defi ..read more
Jens Gustedt's Blog
9M 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
Jens Gustedt's Blog
10M 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
Jens Gustedt's Blog
10M 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
Jens Gustedt's Blog
10M 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
Jens Gustedt's Blog
1y 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
Jens Gustedt's Blog
1y 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