Skip to main content
12 votes
3 answers
2k views

This answer says that i = 1; f(i++, i) will not evaluate to f(2, 2) since C++17. However, I'm struggling to understand why this would have been possible before C++17. What operations, and in what ...
FluidMechanics Potential Flows's user avatar
2 votes
5 answers
330 views

I have read about undefined behaviour for the C3 language here: https://c3-lang.org/language-rules/undefined-behaviour/ Here is the example from the page. Assume following code: uint x = foo(); uint z ...
rhall's user avatar
  • 118
0 votes
0 answers
106 views

This question is a follow-up of std::bit_cast padding and undefined behavior. This "revival" is motivated by my answer to Accessing object storage where I proposed a function to modify a ...
Oersted's user avatar
  • 3,914
2 votes
2 answers
122 views

I'm asking this question from the perspective of a compiler developer – I want to know whether a particular potential optimisation is valid (because all programs that the optimisation would break have ...
ais523's user avatar
  • 2,464
8 votes
1 answer
877 views

Does the code below contain undefined behavior (UB)? struct A { int x; char y; }; int main() { std::vector<uint8_t> v(sizeof(A), 0); A* p = reinterpret_cast<A*>(v.data());...
Dmitriano's user avatar
  • 2,550
3 votes
2 answers
315 views

I see many places in public repositories, where the first and last iterators of std::vector/std::string/std::string_view are converted into pointers using the combination of &* operators. In ...
Fedor's user avatar
  • 24.9k
10 votes
1 answer
530 views

The order of bits in C11 bitfields is implementation-defined, and so is any padding in between them. This makes it difficult to access the bitfields by index at runtime, even though most ...
jpa's user avatar
  • 12.5k
Advice
1 vote
9 replies
211 views

unsigned int n = 1; char* s = "X" + 1; s[-n]; Is that third statement undefined in C23? It seems it is, as by the standard in 6.5.2.1.2: ... The definition of the subscript operator [] is ...
Kyle's user avatar
  • 1,116
1 vote
4 answers
203 views

As far as I understand, you are allowed to access inactive members of a union, if they share a "common initial sequence" with an active one. This can be used to tag active member with a type ...
Dominik Kaszewski's user avatar
6 votes
1 answer
157 views

While looking at this example: https://github.com/PacktPublishing/Hands-On-Design-Patterns-with-CPP-Second-Edition/blob/main/Chapter06/09_function.C which is an implementation of std::function with ...
luczzz's user avatar
  • 446
2 votes
1 answer
116 views

I am trying to hide some implementation behind an opaque data type. Normally, pimpl would be the preferred pattern, but it requires heap allocation which is not desirable in this context (embedded, ...
Dominik Kaszewski's user avatar
5 votes
1 answer
254 views

In C, this is legal as far as I know (In C, does a pointer to a structure always point to its first member?). #include <stdio.h> typedef struct { char *name; int age; } A; typedef ...
Malyutin Egor's user avatar
3 votes
1 answer
186 views

Let's say we have a global state OK inside an UnsafeCell, and instead of unsafe { OK.get().as_mut().unwrap() } every time, we create a convenient getter get_mut. Is it UB to call get_mut inside the ...
curbalman's user avatar
0 votes
0 answers
116 views

Today I stumbled upon weird behavior of std::is_invocable_r. While doing research for why it is happening, I stumbled upon this question on Stack Overflow: is_invocable_r ignoring the return parameter ...
CygnusX1's user avatar
  • 22.1k
1 vote
2 answers
213 views

Is data race undefined behaviour only for two threads within same process, or is it UB also between processes? Definition of Data Race from Rustonomicon: Safe Rust guarantees an absence of data races,...
Samuel Hapak's user avatar
  • 7,284

15 30 50 per page
1
2 3 4 5
193