Most active questions
1,832 questions from the last 7 days
Advice
7 votes
9 replies
209 views
How do you learn without AI
This isn't a joke or a shitpost, I'm being completely serious. I started coding a few years ago and I don't know where to find resources for how to code. Right now I'm working on a messaging app with ...
18 votes
1 answer
2k views
Whose responsibility is it to destroy a C++20 coroutine that throws from its initial suspend?
I am trying to track if a C++20 coroutine has ever suspended, so that unhandled_exception knows whether it can simply re-throw; the exception back to the caller of the initial coroutine function, or ...
0 votes
3 answers
301 views
What are non trivial destructors in C++ used for
I am new to C++, I came from Python where there are constructors but no destructors. What is the point of them if the memory is automatically freed when the object goes out of scope ?
Best practices
3 votes
9 replies
216 views
Better key candidate, std::int16_t or std::int_fast16_t?
In a framework that makes use of the std::int* types (such as std::int16_t) as well as the std::int_fast* types (such as std::int_fast16_t) there could be general rules where one could be better than ...
Advice
0 votes
6 replies
196 views
C++ compile type endianness for use in macros
I need to layout a structure in two different ways depending on the endianness of the target platform. Currently I'm using an additional pre-compile phase to run a program to test the endianness, and ...
Advice
0 votes
4 replies
184 views
Why does GCC transform a >= 4 into a > 3 at -O0? JG seems to be more complex than JGE
Title: Why does GCC transform a >= 4 into a > 3 at -O0? JG seems more complex than JGE I'm analyzing a simple C code on godbolt and found GCC's code generation puzzling: long a; a = a >= 4; ...
9 votes
1 answer
607 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(...
Advice
0 votes
7 replies
125 views
How can this code make me look better as a programmer
#!/usr/bin/python import sys,os,math,random,time, json # import everything badly GlobalVar = 0 globalList = [1,2,3,4,5,6,7,8,9,0] class myclass(object): def __init__(Self,Name="bob",age=...
9 votes
1 answer
475 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*...
11 votes
1 answer
618 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&...
3 votes
2 answers
185 views
Problem with satisfying a C++ concept in a std::visit
I've a C++ concept where I need to check that the class has a particular public attribute. My problem is that the concept works if I use it directly, but fails if I use it in std::visit. This is the ...
Best practices
3 votes
9 replies
130 views
Calling associated fuction on a complex type
I want to write T::associated_function(..) but sometimes T is too verbose to write, like a long tuple. Is there any way to avoid writing the full T? pub trait Param { fn encode_type(out: &mut ...
9 votes
1 answer
419 views
Getting notified when X11 window is minimized and restored
How can I get notified when the user minimizes or restores my X11 window? On very old Linux versions I could check for the UnmapNotify message to learn when the window is minimized and MapNotify when ...
4 votes
2 answers
125 views
Getting a build-time unique ID for a member function within a class
I need to get a unique ID which I could use as a template argument (which means it must be statically determined at compile-time), for each member function of my class. My first idea was to use the ...
0 votes
3 answers
89 views
Would a 500+ case switch statement be possible with 8KB of CPU instruction cache? What alternative should I use?
Okay, this isn't exactly a typical programming situation. I wanna make a pokemon-like homebrew game for the nintendo DS (I know I could use C++, but I only know C so I'm just trying to code in C for ...