Questions tagged [c23]

C23 is the informal name of the next standard of the C programming language. It replaces C17 and introduces some new features.

Important Note: All C related questions, shall be tagged as , and then as a complement, each should specify the version of the standard it is using. In case of the next standard, this complement should be the tag. Please see the tag for details.

29 questions
10
votes
2 answers

Does nullptr_t break type punning or pointer conversions?

Consider this union: typedef union { void* vptr; nullptr_t nptr; } pun_intended; nullptr_t is supposedly compatible with void* 1). Ok so what if we initialize the void* to some non-zero value? pun_intended foo = { .vptr = (void*)42 };…
Lundin
  • 195,001
  • 40
  • 254
  • 396
9
votes
3 answers

C23 auto vs C++11 auto

The C23 standard apparently has introduced using "auto" keyword for auto type deduction, see here, just like in C++11. However, there seems to be some differences. According to here, https://en.cppreference.com/w/cpp/keyword/auto, after C++11, auto…
Mr User
  • 205
  • 1
  • 5
6
votes
1 answer

Why does the C23 standard decrease the max size of an object the implementation must support?

I'm currently reading the new draft of the C23 standard (N3088), and I've noticed that in §5.2.4.1 the standard states: The implementation shall be able to translate and execute a program that uses but does not exceed the following limitations for…
meniadin
  • 63
  • 4
6
votes
1 answer

What is the purpose of the new C23 #embed directive?

A new preprocessor directive is available in the upcoming C23 Standard: #embed Here is a simple example: // Placing a small image resource. #include void show_icon(const unsigned char *, size_t); int main (int, char*[]) { static…
chqrlie
  • 131,814
  • 10
  • 121
  • 189
5
votes
5 answers

How to use typeof_unqual to avoid compiler warnings about discarding const qualifier

In the following code, copyThing() is written so that its return value has the same type as its argument value: extern void *copyThingImpl(const void *x); #define copyThing(x) ((typeof(x)) copyThingImpl(x)) void foo(void); void foo(void) { …
Peter Eisentraut
  • 35,221
  • 12
  • 85
  • 90
5
votes
3 answers

How can I use "nullptr" for null pointers prior to C23?

In C23, the nullptr keyword got standardized. I would prefer to use nullptr instead of NULL prior to C23 too because it means that I could write code which compiles in: C, prior to C23 C, since C23 C++ I could simply use NULL in both languages and…
Jan Schultke
  • 17,446
  • 6
  • 47
  • 96
5
votes
1 answer

C2x: 6.9.2 External object definitions: why is "shall not be an incomplete type" placed in Semantics rather than in Constraints?

Follow-up question for: What is the rationale for "semantics violation does not require diagnostics"?. N2596 working draft — December 11, 2020 ISO/IEC 9899:202x (E), 6.9.2 External object definitions, Semantics, 3: If the declaration of an…
pmor
  • 5,392
  • 4
  • 17
  • 36
4
votes
1 answer

What are the [[reproducible]] and [[unsequenced]] attributes in C23, and when should I use them?

C23 introduced the attributes [[reproducible]] and [[unsequenced]]. What is the motivation behind them? How are they defined, and what effect do they have on a function? What kind of functions should I apply them to?
Jan Schultke
  • 17,446
  • 6
  • 47
  • 96
4
votes
2 answers

Why is strnlen() not considered for inclusion in C23?

Functions strdup() and strndup() have finally made it into the upcoming C23 Standard: 7.24.6.4 The strdup function Synopsis #include char *strdup(const char *s); The strdup function creates a copy of the string pointed to by s in a…
chqrlie
  • 131,814
  • 10
  • 121
  • 189
3
votes
2 answers

Is there an equivalent of __attribute__((nonnull)) in C23?

Several compiler vendors have implemented a non standard extension __attribute__((nonnull)) to specify that a pointer must not be a null pointer. C99 introduced a new syntax to specify that a function argument must point to the first element of an…
chqrlie
  • 131,814
  • 10
  • 121
  • 189
3
votes
1 answer

Can strlen be [[unsequenced]]?

The wording of the C23 working draft on unsequenced functions is unclear to me. Among other properties, unsequenced functions have to be independent: (6) An object X is observed by a function call (6.1) if both synchronize, (6.2) if X is not local…
Jan Schultke
  • 17,446
  • 6
  • 47
  • 96
3
votes
3 answers

What is the difference between C++11's constexpr and C23's [[reproducible]]?

C++11 added the constexpr keyword which can be added to functions to specify constant behavior. C23 added what seems to be identical functionality in the form of the [[reproducible]] tag. How are these two mechanisms different?
Badasahog
  • 579
  • 2
  • 19
3
votes
1 answer

What is the alignment requirement of malloc(1)

I have heard that a successful call to malloc() returns a pointer suitably aligned for any type. Yet it seems useless and wasteful to require malloc(1) to return a pointer aligned for a larger value than 1 since no object larger than char can be…
chqrlie
  • 131,814
  • 10
  • 121
  • 189
3
votes
2 answers

Initialize block-scope static const variable with pointer to compound literal?

The following code is rejected by GCC and Clang (godbolt link): struct thing; typedef enum { THING_TYPE_A, THING_TYPE_B, } thing_type_t; typedef struct thing_a { int i; } thing_a_t; typedef struct thing_b { struct thing const *t; }…
Charles Nicholson
  • 888
  • 1
  • 8
  • 21
3
votes
1 answer

Looking for stdckdint.h in the gcc 11.2 collection

I'm trying to find a copy of stdckdint.h, which I assume should be in the gcc 11.2 collection, but a search fails to locate it in the downloaded source tarball. Is it not public yet, or do I have to unpack/build something to get the include files?
Ian
  • 1,507
  • 3
  • 21
  • 36
1
2