Skip to main content

All Questions

Tagged with
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
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
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
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
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
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
18 votes
5 answers
3k views

Are int main() and int main(void) equivalent prototypes in C23?

C23 introduced new semantics in function declarators: 6.7.6.3 Function declarators [...] 13   For a function declarator without a parameter type list: the effect is as if it were declared with a ...
chqrlie's user avatar
  • 142k
10 votes
2 answers
280 views

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 ...
Lundin's user avatar
  • 208k
3 votes
2 answers
310 views

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 ...
chqrlie's user avatar
  • 142k
3 votes
1 answer
242 views

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 (...
Jan Schultke's user avatar
  • 36.1k
3 votes
1 answer
187 views

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 ...
chqrlie's user avatar
  • 142k
3 votes
2 answers
243 views

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 ...
Charles Nicholson's user avatar
12 votes
1 answer
8k views

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 <stddef.h> void show_icon(const unsigned ...
chqrlie's user avatar
  • 142k

15 30 50 per page