Most active questions
1,981 questions from the last 7 days
24
votes
6
answers
20k
views
Google Antigravity (Gemini 3 Agentic IDE) Stuck in "Setting up your account" Infinite Load [closed]
I'm trying to get started with the Google Antigravity platform (the new Gemini 3 agentic IDE), and I'm hitting a wall right at the very beginning—the account setup phase.
The Issue I'm Seeing:
I ...
Advice
1
vote
22
replies
304
views
Is there a reason why signed integer is used for the ssize_t?
From the man pages, I found that size_t has the range of 0 to SIZE_MAX, and ssize_t has the range of -1 to SSIZE_MAX. So, after printing those values on a 64bit system, I have the following results:
...
11
votes
7
answers
1k
views
Is it possible to expose C++ template struct (fully specialized) to C?
I want to use circular queue with different types and lengths in a project which mainly consists of C code. I'm thinking about implementing the circular queue as a C++ template struct. How to expose ...
Advice
0
votes
11
replies
196
views
Casting functions with pointer arguments to function pointers with void* argument
The following code is accepted by GCC and the resulting binary prints the expected results. But is it standard conform and would always work on different systems using different compilers?
Minimal ...
8
votes
1
answer
848
views
Is there any way to iterate data members with STL algorithms using the C++26 reflection?
With C++26 reflection, we can simply iterate all data members of an object:
#include <iostream>
#include <meta>
struct Foo {
int x;
int y;
};
void PrintFoo(const Foo& foo) {
...
10
votes
1
answer
496
views
Why does std::thread::Scope::spawn need the bound `T: 'scope`?
The signature of std::thread::Scope::spawn looks like this:
pub fn spawn<F, T>(&'scope self, f: F) -> ScopedJoinHandle<'scope, T>
where
F: FnOnce() -> T + Send + 'scope,
...
1
vote
6
answers
223
views
Why do we need abstract methods in Enums
I've been studying Java for some time now to better understand what goes on inside some of the code parts.
While studying Enum, which I am used to using exclusively for listing various fixed values (...
3
votes
2
answers
234
views
Is it ok to write `&*string.end()`?
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 ...
Best practices
3
votes
12
replies
186
views
SpellNumber Simplified Using LAMBDA() function
Here is the custom function to spell number to words using LAMBDA(). I would appreciate any improvement of the function or simplification if possible. Also suggest best practice for the function.
=...
5
votes
4
answers
253
views
How to force the Application.Run to wait for all async void handlers?
I have a Windows Forms application and a Form with many async void event handlers. This form can be closed by the user at any moment. After closing the form I want to delete a temporary file, and my ...
8
votes
1
answer
648
views
When is reinterpret_cast UB?
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());...
10
votes
3
answers
1k
views
Is creating an object not the same thing as starting its lifetime?
I've always assumed that "creating an object" is the same thing as "starting its lifetime" (and not the same thing as allocating storage for it).
But I've recently been told that &...
Advice
0
votes
6
replies
307
views
Dynamic list of type at compile time
I'm looking for a way to store type "dynamicly" in a using (or concret implementation) that would be modifable and accessible at compile-time.
I would like something like:
struct ...
10
votes
1
answer
493
views
Is this a well-defined way to access bitfield bits by index in C11
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 ...
2
votes
3
answers
176
views
Why is a custom specialization of std::hash<std::string> allowed?
I implemented std::hash<std::string> in the usual way, by specializing the std::hash template. But then I realized that these should already be provided by the <string> header (https://www....
5
votes
6
answers
173
views
DistinctBy, but preserve the last element of each group of duplicates
I have a list of items that contains duplicates, and I want to keep the last item of each group of duplicates. The native DistinctBy LINQ operator keeps the first item from each group, so it doesn't ...
Best practices
0
votes
7
replies
154
views
Should I use std::move when returning a local std::string as std::optional<std::string>?
My confusion is about the return statement inside readFileContents:
The function returns std::optional<std::string>, but the local variable is a std::string.
NRVO doesn’t apply here because ...
Best practices
0
votes
11
replies
111
views
How does a recursive function work in PHP?
Edit: How does this recursive call play out, why is i = 1, even though the function fires 3 times ?
Doesn't the function reach the if statement -> fires -> (this repeats 3 times) then reaches ...
Advice
0
votes
5
replies
179
views
Drawing geometric diagrams in R, ggplot
To illustrate the ideas behind discriminant analysis, I created the image below containing a scatterplot with two groups and a plot of the densities of the scores, LD1 on the discriminant function.
...
-1
votes
3
answers
211
views
Why does float f = 3.14; and float f = 3.14f; print the same value in C even though one is double and the other is float?
I am confused about the following behavior in C.
#include <stdio.h>
int main() {
float a = 3.14; // literal is double
float b = 3.14f; // literal is float
printf("%f\n"...
5
votes
2
answers
279
views
Why are C++ and Python giving me different answers, when given (I think) the same precision?
I have this code in C++:
#include <iostream>
#include <iomanip>
#include <limits>
#include <boost/multiprecision/mpfr.hpp>
using namespace boost::multiprecision;
template<...
5
votes
2
answers
180
views
Is there a difference between the C# Volatile.ReadBarrier vs Volatile.Read?
In the released .NET 10 there is a new method added to the Volatile class with the name ReadBarrier().
And I don't know whether from the compilers perspective there is a difference if I do a read with ...
Advice
2
votes
6
replies
83
views
Wait for User Input
I have an HTML page with some data that needs to be saved or discarded before certain other things can be done. I have several functions that will need to pause, wait for the user to make a decision, ...
4
votes
3
answers
144
views
Regex function to extract numbers from string-type values, separated by "-", to get the difference of each two values
I'm 100% new to Regex so I've been floundering about on regex101 trying to figure out how to get my desired output. I am using PostgreSQL to write a query to extract a set of values from the string. ...
5
votes
1
answer
160
views
Why does the same code, one generated by macros and the other handwritten, produces different results in MSVC?
The same code, one generated by macros and the other handwritten, produces different results.I'm lost and don't know how to fix it.
my environment is follow:
vs2019, msvc2019_64, c++14
if using ...
2
votes
2
answers
151
views
I am trying to translate my C code into assembly but my code is not working. What is wrong with it?
I am trying to use an MSP-EXP3430G2ET with a Buzzer and a potentiometer on CCS. The goal of the program is to have 2 modes, a high frequency mode and a low frequency mode. If you press the button, it ...
7
votes
2
answers
181
views
Should a permutation in an ObservableList generate added and removed changes in JavaFX?
I thought that during a permutation in an ObservableList, added and removed changes should not be generated. However, calling FXCollections.reverse() showed that this is not the case. This is my code:
...
9
votes
2
answers
251
views
Nullable warning when upgrading to extension-members syntax
I have two versions of helper methods for logging on ILogger. The first (classic extension methods) compiles fine; the second using extension members results in a compiler warning/error code.
CS8620: ...
Advice
0
votes
7
replies
114
views
C Preprocessor: foreach/macro expansion with loop context
So I've been using this code for generating such statements following This Reddit post:
#define LOOP(seq) END(A seq)
#define BODY(x) int x;
#define A(x) BODY(x) B
#define B(x) BODY(x) A
#define A_END
#...
3
votes
2
answers
132
views
Accessing a union defined as a type [closed]
typedef union
{
unsigned long anyvariable;
float output;
} map;
return (*(map*)&fraction32).output;
I copied this method of accessing the members of a union which ...
0
votes
4
answers
118
views
heap-use-after-free when incorrectly assigning pointers during binary tree inversion [closed]
I was attempting the binary tree inversion question on Leetcode
https://leetcode.com/problems/invert-binary-tree/
I came up with this solution
TreeNode* invertTree(TreeNode* root) {
if (root ==...
Advice
1
vote
13
replies
104
views
C# - lock multiple methods or entire class to single thread execution
I am trying to ensure that methods in my class can only be called by a single thread.
So far tried to use ReaderWriterLockSlim to achieve this effect but this can cause potential issues if it is not ...
Advice
0
votes
13
replies
212
views
JDK 21 What is the point of wrapping a FileReader/InputStreamReader in a BufferedReader?
Java Tutorials site shows this example when discussing character streams:
//The CopyLines example invokes BufferedReader.readLine and PrintWriter.println to do input and output one line at a time.
...
-2
votes
2
answers
224
views
Where in their documents do implementations state they won't reorder black-box functions?
Consider this example:
extern void black_box_foo();
extern void black_box_bar();
int main(){
black_box_foo(); // #1
black_box_bar(); // #2
}
#1 and #2 are functions whose definitions are ...
2
votes
3
answers
166
views
Issue trying to aggregate wind directions on a hourly basis, i.e. computing vector averages of wind data
I need to calculate hourly averages of wind directions using proper vector averages. Arithmetic averages result in the issue where averaging 350° and 10° gives 180° instead of 0°.
The following is the ...
Best practices
0
votes
3
replies
73
views
How do I count values in one column depending on values in another column?
What I have:
I have a dataframe with approx. 20,000 data records.
In the first column are the names of employees ... in the second the value “participated” or “did not participate”.
Each row ...
3
votes
1
answer
159
views
compiles when returning a non-const std::vector but fails when returning a const std::vector
In the below code, I return a std::vector<A> from the get() function. If I make the std::vector<A> be a const type, the compilation fails, otherwise it passes. Can somebody explain this ...
Best practices
0
votes
8
replies
169
views
One-line call to std::optional::emplace only if it has no value
In the same spirit than the creation of an instance in a std::map when calling operator[] , I would like to emplace (direclty in the expression) in an std::optional only if has_value() is false. In ...
0
votes
1
answer
158
views
Input memory leak? [duplicate]
In my homework assignments I've got a task to get an input using scanf() of an integer number and check if its a positive negative or zero.
I've coded this:
#include <stdio.h>
int main()
{
...
Best practices
1
vote
4
replies
114
views
In Java, should I use `@Override` for record fields?
If my record implements an interface, with a field accessor implicitly implementing a method, it should be an instance of what the @Override annotation is meant to cover.
interface I { int f(); }
...
2
votes
2
answers
112
views
Unexpected behaviour from minimax algorithm
I recently started learning C and as a learning project I tried creating a tic tac toe bot using the Minimax algorithm. Here is the code that I have written so far:
#include <stdbool.h>
#include ...
-1
votes
1
answer
211
views
What are the disadvantages of std::try_lock()?
I am currently studying the work of the mutex and I have a question, if we have the std::try_lock() method, then why not always use it instead of std::lock(), what are its disadvantages?
For example, ...
1
vote
1
answer
128
views
Why does my multithreading/pointers code print random values?
My code should print the numbers given as command line arguments. Instead it prints random-looking values.
What is going on and how can I fix it?
#include <stdio.h>
#include <pthread.h>
#...
3
votes
2
answers
112
views
Code is returning "[C Kernel] Executable exited with code -11", don't know what's wrong with it?
I'm working on this piece of code as part of my coursework, ideally any advice I get for this would be educational in some way; I don't want an exact answer, just need someone who knows more than I do ...
3
votes
2
answers
117
views
Cannot get command line code to run via python
I am running python 3.13.5 via PowerShell in windows 10. I can successfully run the folowing command, and now want to run it with a python script
& 'D:\realesrgan\realesrgan-ncnn-vulkan.exe' -i 'D:...
Advice
0
votes
8
replies
109
views
Why does Git not support nested branching, and how can I design a versioning system that does?
I’m building a file versioning system for my product ThinkNCollab, which includes both a Task Management System and an advanced File Versioning System.
While designing the CLI for the versioning ...
8
votes
1
answer
174
views
If I start two strictly CPU bound threads bound to the same CPU, and one is SCHED_IDLE, why does it ever schedule?
If I start two threads bound to CPU 0, where one is SCHED_IDLE, then why is it ever scheduled when the other thread is CPU bound at either normal priority, or at SCHED_FIFO?
For SCHED_FIFO I get it, ...
4
votes
2
answers
91
views
kable_minimal() giving stripes in Quarto table HTML output
I have a Quarto doc rendering to HTML written in R and I would like a table without stripes. All of the kableExtra tables give me stripes. How do I get rid of the stripes?
---
title: "Test"
...
3
votes
3
answers
130
views
How to retrieve a sub-array from result of array_agg?
I have a SQL table in postgres 14 that looks something like this:
f_key
data1
data2
fit
1
{'a1', 'a2'}
null
3
1
{'b1', 'b2'}
{'b3'}
2
2
{'c1', 'c2'}
null
3
Note that data1 and data2 are arrays.
I need ...
5
votes
1
answer
103
views
What's the difference between `extern "C" /*...*/` and `extern "C" { /*...*/ }`
Both GCC and Clang reject
extern "C" static void foo() {}
but accept
extern "C" {
static void foo() {}
}
Aren't these supposed to be equivalent?