{"id":6206,"date":"2024-01-20T00:01:26","date_gmt":"2024-01-20T08:01:26","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=6206"},"modified":"2024-01-27T09:03:00","modified_gmt":"2024-01-27T17:03:00","slug":"new-c23-language-features","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=6206","title":{"rendered":"New C23 Language Features"},"content":{"rendered":"<p>While other programming languages seem to improve and update in great leaps, C moves at a glacial pace. The C23 upgrade offers a few new and exciting features, but nothing I would call impressive or awesome.<br \/>\n<!--more--><br \/>\nFor example, one of the new decimal floating-point math function is <em>decodedecdN()<\/em>. I have no idea what it does and neither does the Internet. Decimal representation of floating point values reduces rounding errors, yet no other specifics are available on how this or the other <em>dN<\/em> functions behave.<\/p>\n<p>The C23 library supports UTF-8 characters with the addition of the <em>char8_t<\/em> data type and two new functions: <em>mbrtoc8()<\/em> and <em>c8rtomb()<\/em>. These functions convert between the multibyte character format and UTF-8. They&#8217;re prototyped in the <code>uchar.h<\/code> header file.<\/p>\n<p>The <em>memset_explict()<\/em> function works like <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=5242\"><em>memset()<\/em><\/a>, but is safe for sensitive information. This function supersedes the non-standard <em>memset_s()<\/em> function for securely writing to a buffer.<\/p>\n<p>The following POSIX functions are now part of the standard C library: <em>memccpy()<\/em>, <em>strdup()<\/em>, <em>strndup()<\/em>, <em>gmtime_r()<\/em>, and <em>localtime_r()<\/em>.<\/p>\n<p>The C23 standard introduces the <em>timespec_getres()<\/em> function, defined in the <code>time.h<\/code> header file. This function uses a <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=5862\">timespec structure<\/a>, which holds time values including nanoseconds.<\/p>\n<p>Other new features include header files <code>stdbit.h<\/code> and <code>stdckdint.h<\/code>, neither of which I have access to so I can only guess what they do.<\/p>\n<p>Also added a slew of testing macros for various versions, such as <code>__STDC_VERSION_MATH_H__<\/code> which I can guess returns the version number for the math library. Again, official documentation is scant.<\/p>\n<p>Four new preprocessor directives are available: <code>#elifdef<\/code> and <code>#elifndef<\/code> work to create <em>if-else<\/em> decision trees for defined constants. Most likely, these directives work with <code>#ifdef<\/code> and <code>#ifndef<\/code> to truly weed out definitions.<\/p>\n<p>The <code>#error<\/code> and <code>#warning<\/code> preprocessor directives throw compiler error and warnings, respectively. The <code>#error<\/code> directive is followed by a diagnostic message that&#8217;s output, then the build stops. The <code>#warning<\/code> directive is also followed by a diagnostic message to output, though this directive doesn&#8217;t halt the build.<\/p>\n<p>Two new pragmas are available to set rounding direction: <code>FENV_ROUND<\/code> and <code>FENV_DEC_ROUND<\/code>. I&#8217;ve found no details are available on what these pragmas do.<\/p>\n<p>To me, most of these features seem esoteric, though I can see how they&#8217;re necessary. C must maintain consistency, so features many programmers may desire will never make the cut. Further, these new features are completely implemented on any compiler I can find. I figure they&#8217;ll slowly evolve over the years, just like the rest of C.<\/p>\n<p>For <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=6216\">next week&#8217;s Lesson<\/a>, I conclude my survey by revealing which C features have been removed and which are now deprecated with the C23 standard.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The C23 flavor offers some new features and functions, but not as many as I would have liked. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=6206\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-6206","post","type-post","status-publish","format-standard","hentry","category-main"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6206","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6206"}],"version-history":[{"count":4,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6206\/revisions"}],"predecessor-version":[{"id":6230,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6206\/revisions\/6230"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6206"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6206"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}