69 questions from the last 7 days
0
votes
0
answers
24
views
VTK rendering window doesn't display
I have recently tried installing VTK 9.5 on Ubuntu 24.04 from source (latest .tar.gz release) but when I compile a really simple example code the window doesn't show up. I would like my vtk ...
0
votes
0
answers
42
views
How to verify a possible execution is OOTA?
Consider this example:
#include <thread>
#include <atomic>
int main(){
std::atomic<int> x = 0, y = 0;
auto t1 = std::thread([&](){
if(x.load(std::memory_order::relaxed)==...
0
votes
2
answers
86
views
How to pass 2D array to function that the size is declared by user input [duplicate]
So the question given to me is to make a C++ program where the user inputs the size (declared by n) of a matrix N x N, and then there's a function for the user to fill the matrix called inputMatrix
#...
0
votes
0
answers
47
views
OpenCV producing completely black mask from image
I'm attempting to narrow a screenshot of an app to a specific section of the UI for later processing by Tesseract; in particular, the X Battle ratings located in the lower half of the image.
I did a ...
1
vote
0
answers
72
views
Why does Clangd warn when using C++20 designated initializers with uniform initialization syntax?
According to modern C++ guidelines, we should prefer uniform initialization everywhere, for example:
int x{0};
However, when I try to combine uniform initialization with C++20’s designated ...
4
votes
2
answers
112
views
How to cause a linker error when an externally-defined macro is inconsistent across translation units?
I'm writing a header-only library which defines class X in header x.hpp. The implementation of X is different for different standard versions:
#if __cplusplus < 201703
class X {
int a; ...
0
votes
0
answers
31
views
Win32 C++: Get path of Portable Device file to enable Copy/Paste
In a previous thread I asked about listing real filenames stored on a Portable Device (e.g. an MTP Digital Camera). Per my answer I can now traverse the file system and display real filenames.
Now I ...
Advice
3
votes
7
replies
220
views
Why do people use macros to declare namespaces in c++?
Off the top of my head, I only remember LLVM's standard library do this, but I remember seeing other libraries also do this. I'm not entirely sure what is the advantage here. I feel like namespace std ...
-1
votes
1
answer
64
views
Creating a MsQuic/Nghttp3 WebTransport Server
The idea is for my Windows app to exchange QUIC data with a browser.
Upon creating a server with msquic and nghttp3, I'm not sure why chrome says
Failed to establish a connection to https://host.com:...
0
votes
0
answers
82
views
Weird linker error "undefined reference to `__imp__vsnprintf'" in "libcrypto.a" in C++ Windows project?
I've been working on a C++ project. I have been using 2 Windows PCs for building it and both worked fine with the same (kinda janky) setup. I recently got a new computer and I get a linker error. My ...
-5
votes
0
answers
81
views
VS Code and GCC claims vulkan.h is missing despite include directory [closed]
I am on Windows 11. I downloaded and installed the Vulkan SDK on my Windows machines. When I try to compile, I keep seeing:
vulkan/vulkan.h: No such file or directory
I have installed:
C:\VulkanSDK\1....
-3
votes
0
answers
72
views
Whitesmith autoindentation of C/C++ code in VSCode [duplicate]
How can I get autoindentation to use Whitesmith style for C/C++ files in VSCode? I use Microsoft C/C++ Extension pack and clang-format. "Format Document" works ok with C/C++ files.
-3
votes
0
answers
84
views
How to properly manage vertical offset for ghosts oscillating between tiles in Pac-Man ghost house [closed]
I am implementing ghost behavior in a Pac-Man clone, specifically the behavior when ghosts are inside the ghost house during the waiting phase.
The issue is that ghosts inside the ghost house do not ...
-3
votes
0
answers
110
views
How to write delete correctly for the allocator [closed]
I have a solution where I need to write a custom allocator that uses a std::vector as storage for the objects allocated with it. I'm using a std::shared_ptr for the std::vector, and I know that it ...
-4
votes
0
answers
76
views
Linking Static libraries to one DLL
I am trying to use the Open Cascade library to create a model converter (DLL). The Open Cascade library contains many DLLs and Libs
I have specified the additional libraries
TKDEGLTF.lib
TKMesh.lib
...
2
votes
1
answer
161
views
diverging std::atan2's unit of least precision
I write a cross-platform program for Windows and Linux, and I would like it to behave as similar on both platforms as possible. I use some mathematics in the program, e.g. std::atan2 function calls, ...
-1
votes
1
answer
133
views
Can somebody explain this code and the related concept of variable length list of template parameter [closed]
Can somebody explain what does this code do?
template <typename... Types>
auto maketuple(Types&&... args){
return std::tuple<Types...>(std::forward<Types>(args)...);
}
...
1
vote
1
answer
93
views
Monitor boost io_context availability
I want to set up a watchdog that checks whether the io_context workers can pick up tasks within a reasonable time and are not stuck running long or blocking operations.
To achieve this, I've ...
0
votes
0
answers
129
views
Why does std::unordered_map rehash unpredictably when inserting many elements, and how can I control or optimize it? [closed]
I'm experimenting with std::unordered_map performance in C++20 and noticed that when I insert a large number of elements, the container sometimes rehashes multiple times even though I called reserve() ...
2
votes
1
answer
128
views
How to start multiple threads exactly at once?
While evaluating thread pool libraries for short-running tasks, I noticed that they all performed significantly worse than OpenMP. The root cause seems to be that other libraries struggle to start ...
-3
votes
0
answers
90
views
How to properly include other .cpp files into my main project? [duplicate]
I have this part of my code where I have an array and want to compare it with other constant arrays, to find a match. As I am working with Multi-dimensional arrays, I decided to store these constants ...
1
vote
0
answers
61
views
Fixed Length Bytes and Glfw
I can draw a rectangle without errors if I use unsigned int or uint32_t in indices[] and I have 2 questions:
Why do I get a triangle when using uint8_t?
I get nothing if its 2 bytes (uint16_t) ?
No ...
5
votes
0
answers
102
views
WASAPI Application Loopback is unable to record MS Teams
I am trying to develop a system audio recording application which uses the application loopback method provided by WASAPI. I'm basing my implementation upon the Windows classic samples application ...
-5
votes
0
answers
107
views
New version of Visual Studio 2026 gives internal compiler error when compiling reflect.h [closed]
I installed the new Visual Studio 2026, and last I checked reflect.h from reflect-cpp was compiling, but no longer. It gives a internal compiler error C1001.
The version I'm using is 18.0.2 (from the ...
0
votes
1
answer
112
views
Removing the commas in a variadic macro
I want to remove the comma characters inside __VA_ARGS__.
I have found a FOR_EACH implementation, which kind of solves it, but gives cluttered error messages when there is a mistake.
My problem has ...
4
votes
1
answer
138
views
G++14 Anonymous Namespaces And Linker Order: Surprising Behaviour
Given the following three source files (main.cc, a.cc, b.cc):
// main.cc
#include <iostream>
#include <string>
std::string get_a();
int main()
{
std::cout << get_a() << '\n';...
0
votes
0
answers
36
views
jemalloc: setting --enable-prof-libunwind but jemalloc.so has no prof_libunwind support
I'm trying to debug memory issues on an embedded Linux system (C++ application). I want to use jemalloc for it.
I managed to build jemalloc and link my sample application against it, and it detects ...
Advice
1
vote
1
replies
90
views
Constraints in the first template parameter
Why can't we put a constraint on the first type parameter of the concept?
Why can't we use the short form of the concept for non-type parameter?
Why is it possible to specialize concepts only in ...
Best practices
2
votes
5
replies
122
views
C++ Varadic Template Class
I am trying to generalise a class that can accept different types, but also optionally accept multiple types. The class must use virtual functions.
For a single type a specialised class might look ...
-1
votes
0
answers
52
views
Application crashes after SFTP operation, GDB & Valgrind show double-free in MySQL result cleanup
I’m dealing with a repeated crash in a custom Linux application and hoping to get advice or confirmation or suggestion on the root cause.
The application connects to an SFTP server, downloads a daily ...
3
votes
1
answer
116
views
When is the definition of an exported function available to an importing TU?
Consider the following translation unit:
export module Example;
export inline void fn1();
export void fn2();
export void fn3();
void fn1() {}
void fn2() {}
module :private;
void fn3() {}
Firstly, ...
-1
votes
1
answer
130
views
Check, if class member - which is a class - does exist
I refer to this answer.
The example is for the integral type int. Replacing it by a class, the example doesn't work and the expression static int const value = sizeof(f<Derived>(0)); resolves ...
2
votes
1
answer
182
views
Determine if a Type is formattable with given Format String at compile time
I am trying to come up with a way to determine, whether a given format string is valid for a given Type at compile time.
I was expecting for a simple concept to work:
template<typename T>
...
-4
votes
0
answers
109
views
The error line is not present in build output, how can I get it there?
I'm building a Visual Studio solution, consisting out of 54 projects. There are several error lines, the first is:
The system cannot find the file '!(bindpath.bin)\somefile.dll'.
In the output ...
4
votes
0
answers
193
views
+50
Is it impossible that the acquire load returns `1` when the loops in other threads exit?
Consider this example:
#include <atomic>
#include <cassert>
#include <thread>
int main() {
std::atomic<int> strong = {3};
std::atomic<int> weak = {1};
auto t1 ...
11
votes
1
answer
647
views
constexpr self-referencing struct
Consider the following simplified code:
template <class T> class Foo {
T t;
const T* t_ptr;
public:
constexpr Foo(T t): t(t), t_ptr(&this->t) {}
constexpr Foo(const Foo&...
0
votes
0
answers
86
views
Modifying object representation in presence of padding bits
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 ...
0
votes
1
answer
67
views
How to access named capture groups in C++? [duplicate]
On Regex101, I have simple Regex with a named capture group in ECMAScript flavor:
(?<name>.*)
I'm trying to do the same thing in C++:
#include <iostream>
#include <regex>
using ...
Best practices
2
votes
8
replies
186
views
What is the optimal way to define a global constant string in C++20?
I need to define several constant strings that will be used across an entire C++20 project.
I am considering the following options :
constexpr char[] str1 = "foo";
constexpr std::string str2 ...
1
vote
1
answer
94
views
For unity builds is there any tradeoff/correctness issues between #pragma once vs include guards [duplicate]
Suppose I have a unity build:
//impl1.h
//impl1.cpp -> #include s impl1.h
//impl2.h
//impl2.cpp -> #include s impl2.h AND impl1.h
//main.cpp
#include "impl1.cpp"
#include "impl2....
2
votes
0
answers
51
views
How to change hover color of a wxButton
I’d like to know whether it’s possible to change the background color of a wxButton when the mouse is hovering over it. On Windows, I tried handling the enter/leave window events, but it seems the ...
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 &...
3
votes
0
answers
118
views
Out of class definition of constrained member function
Having issues finding a syntax for hoisting constrained member function outside of its class that GCC is happy with. At this point I'm starting to think it's a GCC bug.
struct S {
template<...
9
votes
1
answer
615
views
std::equal_to<void>{}(A1, B1) does not compile, while A1 == B1 compiles in C++26 for unscoped enums?
I noticed a discrepancy between C++23 and C++26 code when using googlemock:
enum A { A1, A2 };
enum B { B1, B2 };
TEST(...)
{
ASSERT_EQ(A1, B1); // compiles fine in C++23 and C++26
ASSERT_THAT(...
2
votes
0
answers
126
views
Is it possible that the assertion can fail with memory_order::relaxed to transfer pointers?
Consider this example:
#include <iostream>
#include <atomic>
#include <thread>
#include <cassert>
int main(){
std::atomic<int> val = 1;
std::atomic<std::atomic&...
9
votes
1
answer
485
views
Why does conversion of a negated `size_t` value to `double` fail?
Consider this code:
#include <cstddef>
#include <iostream>
const double cash = 1000;
int main() {
size_t my_size_t_value = 2;
double my_double_value = -my_size_t_value*...
2
votes
1
answer
108
views
QSqlQuery in Qt6: in-place vs prepared
First of all, Qt version is 6.10.0, testing on Arch Linux rolling. I think I've found a bug in Qt but maybe it's just my fault.
My program asks MariaDB database for some data and displays it in ...
1
vote
0
answers
61
views
Has anyone else experienced significant harmonic distortion with WASAPI loopback?
I am using WASAPI loopback for real time audio visualization, and I am seeing some pretty significant distortion. When I play back a 25Hz tone from Audacity (and other programs) and record the samples ...
5
votes
2
answers
113
views
Qt mouseMoveEvent does not work with QColumnView
I have a QColumnView with a QFileSystemModel attached to it, and I am trying to get information on what file is being hovered over in that model view.
I do have mouse tracking enabled, however it ...
-3
votes
1
answer
153
views
ofstream creates a file, but doesn't open [closed]
I'm trying to open a file as output so that I can write converted model data to my file. The problem currently is, even though the path does exist, and the file is created, it isn't actually open. I'...