Skip to main content

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.

2 votes
1 answer
59 views

Using previously set fields when initializing structure with compound literals

What is the expected behavior of referring to previously set fields, when declaring initial values for a struct using compound literal: Specifically is it ok to: struct foo v = { .v1 = ..., .v2 = .v1+...
dash-o's user avatar
  • 14.2k
1 vote
3 answers
137 views

In C language, are objects that are not explicitly initialized necessarily implicitly initialized?

The question I'm going to ask might be quite long. If possible, please read it through patiently. First of all, let's take a look at the content of §6.7.9 Initialization in C11: ¶8: An initializer ...
user24723440's user avatar
17 votes
0 answers
319 views

realloc(ptr, 0) in C23 - now what?

According to the change log of C23, proposal n2464 was voted-in and implemented, making realloc(ptr, 0) explicitly undefined behavior, whereas it was supposedly implementation-defined in previous ...
Lundin's user avatar
  • 208k
4 votes
0 answers
94 views

Is there such a thing as "function attribute correctness"?

Ok so C23 adds function attributes to the language but I'm not sure if anyone actually considered how they are supposed to be used. Consider this example: [[deprecated]] int foo () { return 0; } [[...
Lundin's user avatar
  • 208k
1 vote
0 answers
66 views

Semantics of functions taking a QChar * when passed a void * or const void *

This is a follow-up to: What is the new QChar* in C23?, where @Lundin showed a sample implementation of a function that takes a QChar * with _Generic, after which I implemented strchrnul() like so: #...
Harith's user avatar
  • 7,235
1 vote
1 answer
113 views

what's the problem of passing parameters to void function in c?

In the C programming language, when you want to declare a function without parameters, you write its signature like this: int foo(void); When you want to declare a function with unspecified ...
David's user avatar
  • 53
2 votes
1 answer
177 views

error: must specify at least one argument for '...' parameter of variadic macro

You can define a variadic macro in C like: #define F(x, ...) f(x, __VA_ARGS__) But calling F as F(a) results in the macro expansion f(a,) which would not compile. So C23 includes __VA_OPT__ to ...
Harith's user avatar
  • 7,235
1 vote
1 answer
62 views

Detecting _BitInt type in _Generic

From ISO/IEC 9899:2024, 6.2.5 Types: ... 5 A bit-precise signed integer type is designated as _BitInt(N) where N is an integer constant expression that specifies the number of bits that are used to ...
Harith's user avatar
  • 7,235
4 votes
1 answer
111 views

Check if array is a VLA at compile-time

@Lundin shows how to check if a passed expression is an array at compile-time here: Lvalue conversion of _Generic controlling expression involving array clang warning wrong?: #define IS_ARRAY(T) ...
Harith's user avatar
  • 7,235
2 votes
1 answer
90 views

Can the expanded code of an inline function differ between 2 translation units?

Say I have a macro UNIQUE_NAME(PREFIX) that concatenates __LINE__ to PREFIX: #define CONCAT2_EXPAND(a, b) a ## b #define CONCAT2(a, b) CONCAT2_EXPAND(a, b) #define UNIQUE_NAME(prefix) ...
Harith's user avatar
  • 7,235
3 votes
1 answer
82 views

How and why use call_once()?

From N3220, §7.28.2.1 “The call_once function”: Synopsis #include <threads.h> void call_once(once_flag *flag, void (*func)(void)); Description The call_once function uses the once_flag pointed ...
Harith's user avatar
  • 7,235
2 votes
2 answers
154 views

What is the __STDC_VERSION__ value for C23?

What is the STDC_VERSION value for C11? asks about C11, and How can I use "nullptr" for null pointers prior to C23? says that the current versions of GCC and Clang define it to a placeholder ...
Harith's user avatar
  • 7,235
3 votes
3 answers
150 views

What are source and execution character sets?

I was looking at the changes in C23, and found this in Annex M of the C23 draft: added @ (U+0040, COMMERCIAL AT), $ (U+0024, DOLLAR SIGN), and ` (U+0060, GRAVE ACCENT, "Backtick") into the ...
Harith's user avatar
  • 7,235
2 votes
0 answers
98 views

Why are there sequence point guarantees for C library functions?

I am looking at the C23 draft standard, but I think this would apply in C11 as well. There are several guarantees about sequence points in relation to function calls in C, such as before the return of ...
Kyle's user avatar
  • 990
4 votes
1 answer
125 views

What is the new QChar* in C23?

cppreference shows these prototypes for strchr(): char *strchr( const char *str, int ch ); (1) /*QChar*/ *strchr( /*QChar*/ *str, int ch ); (2) (since C23) and offers this explanation for the ...
Harith's user avatar
  • 7,235
0 votes
0 answers
46 views

Restrictions on auto keyword for type inference in C2X

int main() { auto status = 203; auto static const str = "Hello"; auto static const strs = {"Hello", "World"}; return status; } From playing around with ...
Harith's user avatar
  • 7,235
3 votes
1 answer
53 views

What's an implementation required to do upon seeing unknown attributes?

C2X has introduced "Attribute specifier sequence", which can be of these forms: 1) standard attribute, such as [[fallthrough]] 2) attribute with a namespace, such as [[gnu::unused]] 3) ...
Harith's user avatar
  • 7,235
2 votes
2 answers
108 views

error: constexpr pointer initializer is not null

I have this very simple program: int main(void) { static constexpr const char *const str = "hello"; } which fails to compile with this error: $ gcc -std=c2x str.c str.c: In function '...
Harith's user avatar
  • 7,235
0 votes
2 answers
87 views

Rationale for allowing unnamed parameters in function definitions

From Annex M of this document: — parameter names may be omitted in function definitions; One use I see for this is not having to cast anything to void, or using an unused attribute. But was that the ...
Harith's user avatar
  • 7,235
0 votes
1 answer
69 views

Finding the size of a file with C23 embed

If I do: static char const file[] = { #embed "this.c" }; And then: static char const copy[sizeof file]; I assume sizeof file would be a compile-time constant and would be the actual size ...
Harith's user avatar
  • 7,235
0 votes
1 answer
52 views

Expressing a pointer to a const function

In C, I can express a pointer to a const function like this: typedef void fun_t(void); const fun_t *fp; (I don't know if the type of fp has any practical use, but it is a real and distinct type; e.g.,...
Erik Carstensen's user avatar
6 votes
1 answer
128 views

Can you declare a C pointer with its own address?

Can I declare a C pointer with an intialization to its own address? void* p = &p; I am specifically concerned with if this is strictly standard compliant in C23 (as the draft currently stands). I ...
Kyle's user avatar
  • 990
0 votes
1 answer
107 views

What new types and operations can take place in a constexpr in C23?

C23 added a keyword constexpr which can be used to define objects as compile-time constants instead of enumerations or macros. For example: constexpr int x = 10; constexpr int y = x+10; // Valid ...
CPlus's user avatar
  • 4,378
4 votes
2 answers
118 views

Function pointer compatibility between single pointer and empty parameter lists

I've been reading about function pointer compatibility, but have not found the following scenario documented as being acceptable (below). With this code, it is allowed (without warnings) to call a ...
zambetti's user avatar
3 votes
3 answers
167 views

How to check if a macro argument is an integer literal in C

I'm trying to do a macro like this: #define STRING(i) \ struct STRING##i \ { \ size_t len; \ char chars[i]; \ } but the problem is this works with constexpr arguments like this: constexpr int ...
Abdulmalek Almkainzi's user avatar
1 vote
2 answers
89 views

How to set a pointer to an integer in a compound literal that is initialized in a function?

I tried to initialise a structure via a compound literal in a function. After solving a part of my problem (see Use of compound literal inside a function to init a variable in C), I have a new problem ...
Stef1611's user avatar
  • 2,263
1 vote
2 answers
96 views

Can __VA_OPT__(,) detect a trailing comma with nothing after it?

While playing with __VA_OPT__(,) I noticed the following behavior. Background First, note that C is fine with trailing commas in an initializer. These are equivalent: int foo[] = { 10, 20, 30 }; int ...
KJ7LNW's user avatar
  • 1,801
0 votes
2 answers
113 views

Consolidating GNU C's and C23's deprecated function attribute

The problem I am facing when using the below macro // Assume that __GNUC__ or __clang__ is defined. #if defined(__has_c_attribute) #if __has_c_attribute(deprecated) #define ...
Harith's user avatar
  • 7,235
7 votes
1 answer
162 views

Existence or not of long_double_t (standard C: C23)

The new standard C (ISO/IEC 9899:2023, aka C23), in the Annex H, several macros and types are defined, relative to real and complex arithmetic, subject to the standard ISO/IEC 60559 (floating-point ...
pablo1977's user avatar
  • 4,423
36 votes
2 answers
3k views

Why isn't the keyword false an integer constant expression in gcc C23?

Latest gcc 13.x (trunk) gives a compiler error (gcc -std=c23) for this code: int* p = false; error: incompatible types when initializing type 'int *' using type '_Bool' How can this be correct? C23 ...
Lundin's user avatar
  • 208k

15 30 50 per page