Would it be possible to turn a Raspberry Pi Pico into a valid storage option for your bitcoin wallet's seed phrase?
Hey guys! I just started getting into coding and thought this would be really cool. Assuming the Pico is not the wifi model (thereby making it airgapped), and it is connected to a monitor and keyboard, would it be possible/safe to write code where the user would be asked security questions, enter whatever credentials they make, and if entered correctly, the code would display their seed phrase? Would there be any way for a tech expert to be able to bypass the security questions and access the seed phrase?
Thanks for your time!
https://redd.it/1fbym99
@r_cpp
Console rpg game
Hey I'm a beginner programmer and I can do some basic programming, stuff like a calculator guessing game etc... I would like to try some more complicated projects like an ascii game (but with relatively simple mechanics) so I can practice OOP etc... do u guys have any good resources?
https://redd.it/1fbutyr
@r_cpp
I've invented a technique that drastically improves C++ compilation times
What are the properties of the technique:
---------------------------------------------------------
It should work with most C++ projects.
Projects with slow-to-compile third-party libraries get massive speed-ups - minutes->seconds, especially when accelerating first-builds and re-builds.
Allows editing core code (eg math/containers) without ever triggering slow / gigantic compilations.
Why is the technique needed:
---------------------------------------------------------
C++ compiles all .cpp files everywhere in your project.
C++ compiles source code in all your third party libraries.
These very often contain no code needed for your compilation.
How to implement the technique:
---------------------------------------------------------
Spider out from the file containing main() and dis-include any unreached cpp file.
Jump the gap from header to source using matching file names (eg. string.h / string.cpp)
Anything ultimately reached might be needed for compilation, anything unreached is unneeded.
But what about XYZ?:
---------------------------------------------------------
My random Lib (eg boost etc) doesn't play-nice with this technique: I've got it working with all types of libs (SDL2, open scene graph, VTK, OpenCV, etc) the requirements are pretty lax and very easy to meet.
What about those cpp files that didn't get compiled! I might have introduced a bug and then not seen it!
Yeah it's a different way of programming, you are always free to compile everything when you want to check, and for CI/CD I do let it use a full compilation, but for day to day programming, not using this technique is kind of insane given how much it accelerates important core coding steps like changing-branches-and-recompiling.
Using this technique gives me random linker errors when I forget to rerun it after changing file includes
Yeah it's something you kind of learn to pickup, if a random linker error comes out of nowhere just means you changed your codes includes and forgot to rerun the program you wrote which implements this technique (mine is called CodeClip btw)
How I came up with the technique:
---------------------------------------------------------
I write lots of C++ code
My friend Khan was complaining that my library was too big to recompile all the time, he wanted me to split it up.
My friend Marcus heard about this and asked "whether I had been keeping my header/source files synchronized (e.g. string.h/string.cpp) for some kind of compilation acceleration reason?" too which I was like 🤔 wait .. WHAT?
My own c++ library is rapidly approaching a million lines - every line is used - but no one project uses more than about ~1-2% of the entire library. (I have around 500 different projects)
Requirements to use this technique:
---------------------------------------------------------
All source and header files need to have matching names - eg h/cpp (ubiquitous convention anyway)
All declarations for a cpp file need to be in that files header (ubiquitous convention anyway)
All source files need to have a associated header
Why am I distributing this technique:
---------------------------------------------------------
I've been using it daily for years, it really does work.
It's just a bit too weird / hard to explain / hard to sell.
I want you guys to improve it and report your new tech.
Best luck to everyone on their cpp projects! Hope that this becomes a standard feature of compilers etc one day!
To those willing to take it, here is a technique which will speed up your compilation at hope or at work by > 10x!
Why about if this is the end?:
---------------------------------------------------------
What if this fills all the code bases with little bugs because nothing fully tested?
Make sure CI/CD doesn't use clip!
It's been a good ride.
Enjoy
https://redd.it/1fbmc7b
@r_cpp
Discounts on Clion ?
After trying multiple IDEs, Clion is the answer.
QT Creator wouldn't even build.
Does Jetbrains offer promo codes on it ?
I'm more than fine with paying for it
https://redd.it/1fbi0tt
@r_cpp
Is Boost library still useful in the modern C++ era?
This is a real question. I used Boost about 10 years ago and wonder if it's still in use and really useful for C++(17?)-20-23 projects.
If so, why is it still useful (according) to you and how does it help you nowadays?
https://redd.it/1fbdwtm
@r_cpp
C++ Modules in 2 minutes
https://youtu.be/lJthG8AIxKM?feature=shared
https://redd.it/1fb8iwn
@r_cpp
Best c++ compiler
Hi, I’m new to coding c++ and am just wondering what is the best compiler. I have just been using programiz, but I just wanted to use a real compiler. My only thing is that it should support c++23; at least partially. Thanks!
https://redd.it/1fb0aqr
@r_cpp
CppCast: Benchmarking Language Keywords
https://cppcast.com/benchmarking_language_keywords/
https://redd.it/1faj6xv
@r_cpp
C++ compilation resources
Hi everyone, I want to learn how compilation works, from preprocession to linking. Can someone suggested me any resources?
https://redd.it/1fa8ukf
@r_cpp
Snake in C++ for Beginners
Hello friends!
I am a senior game developer and have prepared a video for beginners on how to make Snake in C++.
Snake in C++ for Beginners | Programming Basic Concepts
Enjoy!
https://redd.it/1f9ufwh
@r_cpp
Started with C++, switched to Java... Now I’m stuck and losing motivation as a freshman
I’ll be starting college as a freshman in a few days at a Tier 3 college. I have been allotted Computer Science with a specialization in AI/ML (even though it wasn’t my first choice tbh). Before my college allotment, I wanted to learn a programming language, so I began with C++. I made it up to loops and was really enjoying it.
Later, one of my cousins, who works as an ML engineer at a startup with a great package, strictly advised me not to learn C++ and suggested to start learning Java instead. On that advice, I started learning Java, but I couldn’t get myself to enjoy it as much as I did with C++. Gradually, I began avoiding coding altogether, and in the process, I ended up wasting two months.
During this time, I kept looking for alternatives to Java simply because I didn’t like the language. I watched many videos about whether to choose C++ or Java, but most of them recommended going with Java, especially if you’re unsure about your future goals and just want to start coding.
My question is should I stick to Java or go back to C++ or start learning python because of my specialization allotted to me for my college program.
Any help will be appreciated.
https://redd.it/1f9jqux
@r_cpp
Where do you practice stl
Hi all,
Where do you practice stl in c++ for the current thing and for your career in stl
https://redd.it/1f9ggxy
@r_cpp
Can unit tests work with getline?
My program uses getline and during development, I've been testing it by adding typing 1 line at a time into the console. Now I need to turn the program into a header file and use unit tests with the test.cpp file instead. Is it possible to send input to getline from a hardcoded unit test without anyone actually typing in input?
https://redd.it/1f9c4fm
@r_cpp
Casting
Is casting (upcasting or downcasting) iterates every class above it or below it till it reaches the desired class? So its like o(n).
or the compiler knows and just checks if its valid or not and immediately decides to assign or not?
https://redd.it/1f91pc7
@r_cpp
Debugging MPI apps
Hi all,
Do you guys have any trick to debug MPI apps?
I use a script that allow me to attach GDB to the process I want. But I was wondering if you have any ideas?
PS: I don't wanna hear of totalview ;)
https://redd.it/1f8o4zn
@r_cpp
I built an mfa device using ESP32
I would like to share my MFA app built using esp32.
https://github.com/AllanOricil/esp32-mfa-authenticator
https://redd.it/1fbwx7i
@r_cpp
Why does this seg fault while running on vs code but if i upload same files on online compiler it works?
I got this StringWrapper class which have constructor and private variables.
I dont know why but when ever i try to make a object for this class StringWrapper, string\_wrap("Example"); like this it shows no output and if i try to debug it goes seg fault right at int main(). Trying since morning help!!!
Debugger output:
(gdb) file a
Reading symbols from a...
(gdb) break main
Breakpoint 1 at 0x1400016ec
(gdb) run
Starting program: C:\\Users\\....\\a.exe
\[New Thread 13148.0x4d7c\]
\[New Thread 13148.0x3ea8\]
\[New Thread 13148.0x3534\]
Thread 1 received signal SIGSEGV, Segmentation fault.
\_\_\_chkstk\_ms () at ../../../libgcc/config/i386/cygwin.S:126
warning: 126 ../../../libgcc/config/i386/cygwin.S: No such file or directory
StringWrapper::StringWrapper(const char* str)
{
// strncpy(string_array, str, std::strlen(str));
std::cout << str;
strncpy(string_array, str, (max_capacity - 10));
// string_array[std::strlen(str)] = '\0';
string_array[max_capacity-10] = '\0';
// std::cout << this->string_array;
}
IN StringWrapper header file
class StringWrapper{
public:
constructor...
private:
char string_array[max_capacity] where max_capacity = 1048576
};
https://redd.it/1fbogs2
@r_cpp
ranges::collect a cpp23 implementation of Rust collect function
Hello r/cpp!
I would like to share with you my implementation of the rust [collect][1] function : [ranges::collect][2]
In rust, the most common use case of `collect` is to act like `std::ranges::to<container>` but it has an other great feature that I think we are missing in the current ranges standard library:
If the collected range is a ranges of potential_type (ie expected, or optional) you can collect your range of potential value into a potential range of value.
In other words, the return of collect is either the ranges of contained value or the first error encounterd in the range.
This is usefull if you work with the new cpp20 `std::ranges` function and `std::expected` or `std::optional` because otherwise you would had to do something like:
```
//pseudocode
if (found = range_of_exp | find_if(has_value); found != end(range_of_exp)) {
/*treat the error*/
} else {
res = range | transform(&Expected::value) | to<vector>();
}
```
a lot of time in your code base. And if you work on an input range this can start to be annoying as you can't iterate twice on your range.
`ranges::collect` is designed to make this job easier.
**Here is a basic Example**
```cpp
using VecOfExp = std::vector<std::expected<int, std::string>>;
using ExpOfVec = std::expected<std::vector<int>, std::string>;
VecOfExp has_error = { 1, std::unexpected("NOT INT"), 3};
VecOfExp no_error = {1, 2, 3};
ExpOfVec exp_error = has_error | ranges::collect();
ExpOfVec exp_value = no_error | ranges::collect();
/// same as:
// auto result = ranges::collect(no_error);
auto print = [](const auto& expected) {
if (expected.has_value())
fmt::println("Valid result : {}", expected.value());
else
fmt::println("Error : {}", expected.error());
};
print(exp_error);
print(exp_value);
```
**Output:**
```
Error : NOT INT
Valid result : \[1, 2, 3\]
```
There are more possibilities than that, so if you want to know more, you can find more information and examples in the README page on github [Here][2].
And you can even play with it on Compiler Explorer [Here][3]
I think it's a great tool and I'm thinking of making a proposal to add it to a future version of the cpp.
So I'd really appreciate it if I could get your feedback on what you think of the function, what could be improved or what you think could be added.
Have a great day!
[1]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.collect
[2]: https://github.com/jileventreur/collect
[3]: https://godbolt.org/z/4bGo5jfsv
https://redd.it/1fbl8ko
@r_cpp
Web server in C++
I’m planning to build a web server in C++ that can handle multiple virtual servers. Can anyone recommend a good resource or guide for structure the project and its architecture?
https://redd.it/1fbhcfa
@r_cpp
maybeuninit: A C++26 wrapper type of uninitialized values!
Hey r/cpp! I'm sharing a library I developed that provides a non-verbose way of instantiating objects without immediately invoking constructors: [https://github.com/oracle-9/maybe\uninit](https://github.com/oracle-9/maybeuninit)
It's in C++26, so compiler support is a bit finicky, but it's required in order to get `constexpr` placement new (also because I wanted to try out the newest language features).
There's a README in the repo with a more in-depth explanation, but here are some usage examples:
struct NonTrivial {
NonTrivial() = delete;
NonTrivial(int) {}
};
auto nontrivials =
std::array<mem::maybeuninit<NonTrivial>, 10>{}; // NonTrivial() isn't called.
// Construction.
for (NonTrivial& uninit : nontrivials) {
uninit.pareninit(42); // 42 is forwarded, and NonTrivial is constructed inplace inside the maybeuninit.
}
// Destruction.
for (NonTrivial& init : nontrivials) {
init.destroy(); // must be destroyed manually, as maybeuninit doesn't track the object's lifetime like std::optional.
}
It supports parenthesis initialization T(Args...)
(which IIRC corresponds to direct/value initialization depending on the parameter list):
auto u64max = std::numericlimits<std::uint64t>::max();
auto lossy = mem::pareninit<std::uint32t>(u64max); // compiles, possibly with a warning.
auto v = mem::pareninit<std::vector<int>>(10uz, 42); // 10 ints whose value is 42.
As well as brace initialization `T{Args}`:
auto compileerror = mem::braceinit<std::uint32t>(u64max);
auto v = mem::braceinit<std::vector<int>>(1, 2, 3); // {1, 2, 3}
It also provides the member functions ptr
, ref
and bytes
, which allow inspecting the contained value, preserving the value category of *this
.
That's all, any code suggestions are welcome!
https://redd.it/1fbdf2f
@r_cpp
Why does libc++ still not have full C++17 support?
https://en.cppreference.com/w/cpp/compiler_support/17#C.2B.2B17_library_features
https://redd.it/1fb39f1
@r_cpp
Do any IDEs auto generate header files ?
Headers are the only part of CPP I don't really like. I'm largely a C# developer ( been using it for over a decade), so having to write headers is a major shift.
This sounds really lazy, but I'd love a tool that just asks me what fields and functions I need and just generates it.
Taking my first steps into this world...
https://redd.it/1fasqcq
@r_cpp
issues with Padding and Protobuf Message Size Handling
I'm dealing with a problem where I need to ensure that the size of my Protobuf messages is always a multiple of 4 bytes before sending them over a network. I’m using a ProtobufCBinaryData padding
field in my MyEventData
message to handle this, but I'm encountering some issues with the padding size and overall buffer size.static esp_err_t pack_event_data(MyEventData *event_data) {
size_t length = my_event_data__get_packed_size(event_data);
if (length == 0) {
ESP_LOGE(MY_EVENT_TAG, "Failed to get packed size\n");
return ESP_ERR_NOT_FOUND;
}
size_t padding_size = (length % 4 == 0) ? 0 : (4 - (length % 4));
size_t total_length = length + padding_size;
uint8_t *padding_buffer = NULL;
if (padding_size > 0) {
padding_buffer = (uint8_t *)malloc(padding_size);
if (padding_buffer == NULL) {
ESP_LOGE(MY_EVENT_TAG, "Failed to allocate memory for padding buffer\n");
return ESP_ERR_NOT_FOUND;
}
memset(padding_buffer, 0x00, padding_size);
event_data->padding.data = padding_buffer;
event_data->padding.len = padding_size;
} else {
event_data->padding.data = NULL;
event_data->padding.len = 0;
}
uint8_t *packed_buffer = (uint8_t *)malloc(total_length);
if (packed_buffer == NULL) {
ESP_LOGE(MY_EVENT_TAG, "Failed to allocate memory for packed buffer\n");
return ESP_ERR_NOT_FOUND;
}
size_t length_of_packed = my_event_data__pack(event_data, packed_buffer);
if (length_of_packed != total_length) {
ESP_LOGE(MY_EVENT_TAG, "Packed length mismatch: expected %zu, got %zu\n", total_length, length_of_packed);
free(packed_buffer);
if (padding_buffer) free(padding_buffer);
return ESP_ERR_NOT_FOUND;
}
printf("Length of packed_buffer: %zu\n", length_of_packed);
print_hex(packed_buffer, length_of_packed);
free(packed_buffer);
if (padding_buffer) free(padding_buffer);
return ESP_OK;
}
My questions are:
1. How can I accurately manage padding in Protobuf messages to ensure the final size of the packed data is a multiple of 4 bytes without affecting the unpacking process?
2. Actually the requirement for the above question 1 came when I was trying to send the proto of size not a multiple of 4 through spi bridge then some of the data is getting truncataed.if solving 1 is not possible, then tell the potential thing to make the communication through spi bridge without data loss.
Any insights or recommendations would be greatly appreciated!
https://redd.it/1fab5bs
@r_cpp
Understanding the Layout Process in Qt Widgets
https://felipefarinon.com/articles/qt-widgets-layout/
https://redd.it/1f9tz2f
@r_cpp
BLACKJACK COUNTING CODE
I dont know cpp. I used chat gpt to create a cod. can someone help me improve this?
the code simulates a blackjack table with 8 decks, reshuffling after 280 cards +-. does this works? i want to calculate every hand the Running Count and true count (hi-lo). how can i edit the code?
https://filetransfer.io/data-package/cQfFjOjT#link
https://redd.it/1f9m99j
@r_cpp
Structs and constructors
https://www.sandordargo.com/blog/2024/09/04/structs-and-constructors
https://redd.it/1f9fkyr
@r_cpp
best drawable tablet/laptop type thing for programming?
i’m in school and i want a tablet i can take notes on but also can turn into a laptop, either with the addition of a keyboard or a detachable keyboard of some sort that has enough RAM etc for coding also. i’ve looked into like the galaxy s9 but ive heard that’s not the best
https://redd.it/1f90xwo
@r_cpp
Looking for advice on finding a part-time and fully remote C++ job
Hi everyone,
I'm a senior C++ developer with about 10 years of experience, primarily in the game industry. I'm currently based in Belgium, where I run my own solo company. I'm posting here to get some advice or hear about others' experiences regarding my situation.
To give you some context, I am autistic and currently dealing with depression and other health issues, which means my energy levels are quite limited right now. I do feel like I have a lot of skills to bring to the table, but I’m looking for a part-time, fully remote position so I can manage my work alongside my health.
My question is: Is it realistic to find a C++ job that meets these criteria? I often feel like the job listings I see online never quite match what I’m looking for, either in terms of hours required or the ability to work remotely.
If you have any advice, personal experiences to share, or even leads on job offers that might fit, I’d really appreciate it. Any help or suggestions are welcome.
Thanks in advance for your responses!
https://redd.it/1f8wgao
@r_cpp
Qt Creator User Survey 2024
https://www.surveymonkey.com/r/qtcreatorsurvey2024
https://redd.it/1f8q4d0
@r_cpp