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
3
votes
1 answer

Is [[nodiscard]] any different from [[gnu::warn_unused_result]]?

I had some code that used the GCC extension [[gnu::warn_unused_result]] (a.k.a. __attribute__((__warn_unused_result__))). Now I attempted to use C2x's [[nodiscard]] and I got an incomprehensible error. I'm not sure if the usage of [[nodiscard]] is…
2
votes
1 answer

What is the difference between float, _Float32, _Float32x, and _Float32_t?

C23 introduced a number of floating point types, including but not limited to: _Float32 _Float32x _Float32_t I am unsure of the differences, such as: Are they keywords, or are they type aliases, or something else? Are they distinct types, or can…
Jan Schultke
  • 17,446
  • 6
  • 47
  • 96
2
votes
1 answer

What Exactly is the Proposed C23 `_Either` Type?

C23 proposal n3003 and n2366 mention a proposed _Either type in passing on the first page and seventh, respectively, and I have not been able to find any other references to it thus far. As far as I can tell, it is neither mentioned in the C23…
William Ryman
  • 231
  • 2
  • 9
2
votes
1 answer

Implementing std::bit_cast equivalent in C

Is it possible to implement something similar to C++20's std::bit_cast in C? It would be a lot more convenient than using union or casting pointers to different types and dereferencing. If you had a bit_cast, then implementing some floating point…
Jan Schultke
  • 17,446
  • 6
  • 47
  • 96
2
votes
2 answers

Is there a char8_t in C?

I have searched in many sites and did not get anything. I know that char8_t is a keyword in C++ since C++20. I am trying to find out in C, are they typedef-ing unsigned char to char8_t in C23 (with the release of u8 character literals). Can anyone…
Sourav Kannantha B
  • 2,860
  • 1
  • 11
  • 35
1
vote
2 answers

gcc: constexpr functions in C23?

Playing around with constexpr with GCC v14.0 (which should be close to the soon to be released GCC v13.1), I compiled the following module: constexpr int f (int x) { return x + 2; } constexpr const int x[] = { f(1) }; with gcc -std=c2x -c…
emacs drives me nuts
  • 2,785
  • 13
  • 23
1
vote
1 answer

Two types have compatible type if their types are the same: confused

C2x (N2596), 6.2.7 Compatible type and composite type, 1: Two types have compatible type if their types are the same. The grammar of that sentence is confusing. For example: How type can have a type? Or what does "their types" mean? What does it…
pmor
  • 5,392
  • 4
  • 17
  • 36
1
vote
1 answer

Is it considered normal that f = NAN may cause raising floating-point exceptions?

C2x (as well as previous): The macro NAN is defined if and only if the implementation supports quiet NaNs for the float type. It expands to a constant expression of type float representing a quiet NaN. Sample code (t0a.c) #include…
pmor
  • 5,392
  • 4
  • 17
  • 36
1
vote
2 answers

What is the definition of a "valid program"?

ISO/IEC 9899:202x (E) working draft — December 11, 2020 N2596, footnote 9: ... an implementation is free to produce any number of diagnostic messages, often referred to as warnings, as long as a valid program is still correctly translated. It can…
pmor
  • 5,392
  • 4
  • 17
  • 36
1
vote
1 answer

What's the point of the __unused attribute in C?

I've got a question. Let's say you define a function or variable in C. If you don't use it, the compiler generates a warning that this variable/function wasn't used. To suppress the warning, you use the __unused attribute before the declaration. If…
Matthew Schell
  • 599
  • 1
  • 6
  • 19
0
votes
1 answer

How to avoid mentioning a function pointer's arguments inside the definition of a function that takes it as argument?

I'm writing this C code that involves passing around a lot of function pointers, and sometimes writing all the arguments that a function pointer takes when defining a function that takes it as an argument can significantly increase the length of the…
Mehdi Charife
  • 722
  • 1
  • 7
  • 22
0
votes
2 answers

Regarding mainstream compilers and int main(){} in C23

My program: int main(){} In upcoming C23, non-prototype and "K&R style" functions are removed. I realize that C23 is not yet formally released, but the current behavior of gcc and clang is confusing me. Compiling the above with gcc (trunk)…
Lundin
  • 195,001
  • 40
  • 254
  • 396
0
votes
0 answers

why weak attribute has not been selected for C23?

I can see that there is a new keyword type 'attributes' in C23. Some of it, like [[deprecated]] were used in C11+GNU __attribute__((deprecated)). I looks like a great update. I wonder why a usefull keyword as __attribute__((weak)) is not part of the…
Guillaume D
  • 2,202
  • 2
  • 10
  • 37
-4
votes
0 answers

va_start with GCC 13.2, flags not enabling C23 for this method

I am trying to use this functionality, specifically the C23 version so I don't need to pass the second parameter. void va_start( va_list ap, ... ); //(since C23) When running the provider example on cppreference, and choosing GCC 13.1(C23), it…
Andres
  • 1
  • 1
1
2