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.

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