11,832 questions
5
votes
0
answers
227
views
Is there a way to have uninitalized globals in C++? [duplicate]
I am writing an embedded OS to run on Risc-V. As part of that, I'm implementing a FIFO for UART buffering using the classic single consumer/single producer module. The class looks like this:
template &...
1
vote
2
answers
310
views
Can I clean the phrase of the C++ n4928 working draft (regarding mandatory copy-elision during initialization with identical types) like this?
So there is a phrase from the C++ Standard working draft (n4928):
[dcl.init.general] ¶ 16.6.1
If the initializer expression is a prvalue and the cv-unqualified version of the source type is the same ...
0
votes
0
answers
45
views
g++ not showing any error for narrowing conversion with uniform initialization?
I'm very very new to C++ so I hope this question does make sense and is not too ill formed. From my understanding, the uniform initialization {} should forbid any narrowing conversion. So for example ...
0
votes
1
answer
100
views
Flutter Web video player not showing the video
I'm using video_player: ^2.10.0 to display a video as a background in my web app, but it is simply not loading. There is this Video init error:
UnimplementedError: init() has not been implemented.
I ...
0
votes
1
answer
28
views
Re-use variable for the following year GAMS
I have a script in Gtree with GAMS on the carry-over effect on groundwater. I initialised the groundwater depth in the year 2000, and then I need to use the end-of-the-year groundwater depth as a ...
9
votes
4
answers
1k
views
Single-line initialization of array allocated by malloc()
I used malloc to define an index because each line had a different number of elements (simplified example below):
int** Index=malloc(2*sizeof(int*));
Index[0]=malloc(2*sizeof(int));
Index[1]=malloc(3*...
5
votes
2
answers
388
views
Why are gotos allowed to jump initialisation in C but not C++?
Consider this code:
int foo() {
goto lbl;
int a = 4;
lbl:
return 5;
}
With GCC 12, this compiles totally fine as C, not even a warning. However if I try to compile it as C++ I get this ...
3
votes
2
answers
225
views
How can I emulate C++26 erroneous behaviour in earlier versions of C++?
C++26 introduces "erroneous behaviour" for uninitialised data, and introduces the [[indeterminate]] attribute for locals to restore the pre-C++26 behaviour as needed. I want to get ...
0
votes
0
answers
100
views
Why does the Linux kernel use initcalls instead of calling init functions directly?
I’m trying to understand the rationale behind the Linux kernel’s initcall mechanism.
My current understanding:
Kernel subsystems expose one-time initialization functions using macros like ...
2
votes
1
answer
117
views
Initialize array of pointer to struct using compound literals without being verbose
I would like to initialize a NULL terminated array of pointer to struct using compound literals.
Currently, I achieve this by:
struct object
{
int data1;
char data2;
};
struct object *...
2
votes
1
answer
99
views
Initializing Base class and member using the same pointer without UB
While reviewing some testing code, I have come across this situation:
Suppose we have these two classes:
class Project
{
public:
Project(std::string path);
~Project;
// [many more ...
0
votes
0
answers
50
views
How to change the launcher directory of PyTest
I am new to Pytest and Python. I tried to run some test with Pytest but I got this error:
OS: Windows 11 Home
Python version:3.13.5
Pytest version:8.4.1
The command I tried to run is
PS C:\Users\xxxx\...
1
vote
3
answers
210
views
How to determine if a C++ object is default-initialized or left uninitialized?
In C++, how can one programmatically determine whether an object is default-initialized or left uninitialized — without relying on reading the standard, documentation, or source code?
For example:
int ...
2
votes
1
answer
136
views
Why is a field not initialized when using a custom record copy constructor?
I have this record:
record Foo {
string _bar = "initialized";
public string Bar => _bar;
}
I'm running the following code:
var foo = new Foo();
Console.WriteLine(foo?.Bar ?? &...
5
votes
1
answer
124
views
Initializer list with the same designators but different initializers (values): does the C standard explicitly define which one takes effect?
Consider this code:
int x[1] = {[0] = 1, [0] = 2};
Which value x[0] has?
Experimentally the last designator takes effect (i.e. x[0] has value 2). However, does the C standard prescribe that "the ...