Stay up-to-date with everything C++! Content directly fetched from the subreddit just for you. Join our group for discussions : @programminginc Powered by : @r_channels
SDKOpenAI
# The OpenAI SDK for C You've Always Wanted
If you've ever tried integrating the OpenAI API in C, you know it can be a tedious process. That’s why we created SDK\OpenAI, a lightweight, powerful, and flexible SDK designed to simplify using the OpenAI API (or similar services) in C applications.
# What does SDKOpenAI do for you?
With it, you can:
* Send prompts easily and efficiently.
* Define context windows to maintain conversation coherence.
* Use lambdas to process responses dynamically.
* Configure and fine-tune prompts effortlessly.
* Handle HTTPs requests seamlessly. All of this with an intuitive and performance-optimized API, ensuring your code stays clean and efficient.
# Why use SDKOpenAI?
Simplicity \- Integrate AI into your project without hassle. Efficiency \- Low resource consumption and high performance. Flexibility \- Adapt the OpenAI API usage to your needs. Productivity \- Spend less time dealing with technical details and more time creating. If you need a robust AI SDK for C, SDK_OpenAI is the right choice.
...
https://github.com/SamuelHenriqueDeMoraisVitrio/ClientSDKOpenAI
https://redd.it/1jbpotx
@r_cpp
Suggestions for a learning book (very specific context)
Hi,
I’m looking for book recommendations to learn C++ over the summer. To help guide your suggestions, here’s a bit about my background:
I’m a senior computer science teacher with a strong theoretical focus—I spend more time at the chalkboard than behind a keyboard. For the applied parts of my teaching, I have primarily used C (data structures, memory management, etc.) and functional languages. While I wouldn’t call myself a C wizard, I am very comfortable coding in C.
For organizational reasons, I plan to replace one of my courses with "Programming Paradigms," which aligns well with my expertise in procedural and functional programming. However, I will need to cover some object-oriented programming as well.
I am well-versed in the object-oriented paradigm and have worked extensively with Python, but for consistency with my university’s curriculum, I will be using C++. The problem? I have never used C++ before—hence my request for recommendations.
Here are the key factors I’m considering:
I’m not looking for an introductory book.
I’ll be using C++ for the last few years of my career, not for a lifelong programming journey.
My focus is academic—I won’t be dealing with large projects, just single-file programs of 200-400 lines.
I have no interest in libraries.
I prefer books with a solid theoretical and formal foundation over those focused on practical shortcuts.
Most of my CS books are 40-50 years old, so I’m not necessarily looking for the latest publication.
https://redd.it/1jb0im1
@r_cpp
What is current state of modules in large companies that pay many millions per year in compile costs/developer productivity?
One thing that never made sense to me is that delay in modules implementations seems so expensive for huge tech companies, that it would almost be cheaper for them to donate money to pay for it, even ignoring the PR benefits of "module support funded by X".
So I wonder if they already have some internal equivalent, are happy with PCH, ccache, etc.
I do not expect people to risk get fired by leaking internal information, but I presume a lot of this is well known in the industry so it is not some super sensitive info.
I know this may sound like naive question, but I am really confused that even companies that have thousands of C++ devs do not care to fund faster/cheaper compiles. Even if we ignore huge savings on compile costs speeding up compile makes devs a tiny bit more productive. When you have thousands of devs more productive that quickly adds up to something worth many millions.
P.S. I know PCH/ccache and modules are not same thing, but they target some of same painpoints.
https://redd.it/1jb8acg
@r_cpp
EA Command and Conquer SRC
https://github.com/electronicarts/CnCRemasteredCollection/tree/master/REDALERT
Saw this posted in a different subreddit, found it interesting to dig through some 1994 source code.
https://redd.it/1jajlt5
@r_cpp
The best way to avoid UB when dealing with a void* API that fills in a structure?
I am currently working with a C API which will fill a given buffer with bytes representing a one of two possible POD types. And then returns the size of the object that was written into the buffer. So we can know which of the two that was returned by comparing `n` to the size of the one of the two structures (they are guaranteed to be different sizes). Something like this:
struct A { ... };
struct B { ... };
char buffer[1024];
int n = get_object(buffer, sizeof(buffer));
if (n == sizeof(A)) {
// use it as A
} else if (n == sizeof(B)) {
// use it as B
} else {
// error occurred
}
So here's my question. I'm **NOT** using C++23, so I don't have `std::start_lifetime_as`. I assume it is UB to simply `reinterpret_cast`, correct?
if (n == sizeof(A)) {
auto ptr = reinterpret_cast<A *>(buffer);
// use ptr as A but is UB
} else if (n == sizeof(B)) {
auto ptr = reinterpret_cast<B *>(buffer);
// use ptr as B but is UB
} else {
// error occurred
}
I assume it's UB because as far as the compiler is concerned, it has no way of knowing that `get_object` is effectively, just `memcpy`-ing an `A` or a `B` into `buffer`, so it doesn't know that there's a valid object there.
I believe this is essentially the problem that `start_lifetime_as` is trying to solve.
So what's the best way to avoid UB? Do I just `memcpy` and hope that the compiler will optimize it out like this?
if (n == sizeof(A)) {
A obj;
memcpy(&obj, buffer, sizeof(A));
// use obj as A
} else if (n == sizeof(B)) {
B obj;
memcpy(&obj, buffer, sizeof(B));
// use obj as B
} else {
// error occurred
}
Or is there a better way?
Bonus Question:
I believe that it is valid to curry POD objects through `char*` buffers via `memcpy`. So if we happen to **KNOW** that the implementation of `get_object` looks something like this:
int get_object(void *buffer, size_t n) {
if(condition) {
if (n < sizeof(some_a)) return -1;
memcpy(buffer, &some_a, sizeof(some_a));
return sizeof(some_a);
} else {
if (n < sizeof(some_b)) return -1;
memcpy(buffer, &some_b, sizeof(some_b));
return sizeof(some_b);
}
}
Would that mean that the `reinterpret_cast` version of the code above would suddenly **NOT** be UB?
More directly, does this mean that , if the API happens to fill the buffer via `memcpy`, then casting is valid but otherwise (like if it came via a `recv`) it isn't?
This question is interesting to me because I don't see how the compiler could possibly know the difference on the usage end, and therefore would **HAVE** to treat them the same in both scenarios.
What do you guys think? Because in principle, it seems no different from the compilers point of view than this:
char buffer[1024];
if(condition) {
if (n < sizeof(some_a)) return -1;
memcpy(buffer, &some_a, sizeof(some_a));
auto ptr = reinterpret_cast<A *>(buffer);
// use ptr as A
} else {
if (n < sizeof(some_b)) return -1;
memcpy(buffer, &some_b, sizeof(some_b));
auto ptr = reinterpret_cast<B *>(buffer);
// use ptr as B
}
Which, if I'm understanding things correctly, is not UB. Or am I mistaken? Is it only valid if I were to `memcpy` from the buffer back into an object?
https://redd.it/1jafl49
@r_cpp
Polymorphic, Defaulted Equality
https://brevzin.github.io/c++/2025/03/12/polymorphic-equals/
https://redd.it/1ja7su9
@r_cpp
Tips for C++
Hello people of the internet . i am currently learning C++ and wanted to know from your persective what are the most common challenges that most people in the community face when learning the language .
https://redd.it/1j9iri0
@r_cpp
Is GSL still relevant?
Hello! I've started work on modernizing a hobby project I wrote many years ago. My project was written to the C++98 standard, but I would like to update it to use more modern practices that take advantage of the advances in C++ since the early days. I'm using Visual Studio on Windows as my development platform.
Visual Studio has many suggestions for improvements but routinely suggests using GSL classes/templates. I'm not familiar with GSL. After looking into it, I get the impression that many (most? all?) of its components have been or soon will be superseded by Standard C++ features and library components. Do you think that's an accurate assessment? Do people still use GSL? I'm trying to understand its relationship with the broader C++ ecosystem.
Although I'm currently on the Windows platform, I would like to eventually compile my project on Linux (with GCC) and macOS (with Clang). Does that rule out GSL? GSL is supposedly cross-platform, but I'm not sure how realistic that is.
Thanks!
https://redd.it/1j96u8y
@r_cpp
Latest News From Upcoming C++ Conferences (2025-03-11)
This Reddit post will now be a roundup of any **new** news from upcoming conferences with then the full list being available at [https://programmingarchive.com/upcoming-conference-news/](https://programmingarchive.com/upcoming-conference-news/)
If you have looked at the list before and are just looking for any new updates, then you can find them below:
* **ACCU**
* **Attending ACCU Online** – More information about attending ACCU online is now available at [https://online.accuconference.org/](https://online.accuconference.org/)
* **Call For Online Posters Closing Soon** – If you would be interested in presenting a virtual poster in exchange for free access to the online ACCU Conference, please visit [https://online.accuconference.org/posters/](https://online.accuconference.org/posters/) and make your application by **Monday 17th March**
* **Call For Online Volunteers Closed**
* **C++Now**
* **Accepted Sessions Announced –** You can now view the list of 52 accepted sessions for C++Now 2025 at [https://schedule.cppnow.org/cppnow-2025-sessions/](https://schedule.cppnow.org/cppnow-2025-sessions/). Dates and times of each session will be confirmed soon.
* **Call For Student Volunteers Closed**
* **C++OnSea**
* **C++OnSea Call For Speakers Closed**
* **CppNorth**
* **CppNorth Call For Speakers Closed**
* **C++Online**
* **C++Online On Demand & Early Access Pass Now Available** – Purchase an early access pass for £25 which will give you early access to 25 talks and 7 lightning talks. Visit [https://cpponline.uk/registration](https://cpponline.uk/registration) to purchase
https://redd.it/1j8ukhr
@r_cpp
What is the best c++ IDE for games development?
https://redd.it/1j8rn0k
@r_cpp
Zybooks
Does anybody have the zybook C++ test bank?
https://redd.it/1j8bzm1
@r_cpp
Bypassing the branch predictor
https://nicula.xyz/2025/03/10/bypassing-the-branch-predictor.html
https://redd.it/1j89c7p
@r_cpp
C++ needs stricter language versioning
I have developed with c++ for about 4 years now, and the more I learn about the language, the more I grow to dislike it. The language is like an abusive partner that I keep coming back to because I still can't live without it.
The main issues that I have lie in the standard library. The biggest issue that I have with the library is it's backwards compatibility baggage. The newer language versions have excellent features that make the language
1. Compile faster
2. More readable
3. Easier to debug
4. Faster to execute due to better compile time information
The standard library doesn't make use of most of these features because of backwards compatibility requirements.
The current standard library could be written with today's language features and it would be much smaller in size, better documented, more performant, and easier to use.
Some older things in the library that have been superceded by newer fearures could just be deprecated and be done with.
Personally, all features requiring compiler magic should be language features. All of <type_traits> could be replaced with intrinsic concepts that work much better.
We could deprecate headers and have first-class support for modules instead.
C++ would be my absolute favourite language without a doubt if all of the legacy baggage could be phased out.
I would say that backwards compatibility should be an opt-in. If I want to start a new project today, I want to write c++23 or higher code, not c++98 with some newer flavour.
https://redd.it/1j807qm
@r_cpp
GCC support std module with CMake 4.0 Now!
As CMake 4.0.0 and GCC-15 support, we could use cmake like this:cmakelists.txt
:
cmake_minimum_required(VERSION 4.0.0)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "a9e1cf81-9932-4810-974b-6eccaf14e457")
set(CMAKE_CXX_STANDARD_REQUIRED OFF)
set(CMAKE_CXX_MODULE_STD 1)
project(cpptest VERSION 0.1.0 LANGUAGES CXX)
add_executable(cpptest main.cpp)
main.cpp
import std;
int main(){
std::println("Hello world!");
}
Compiling C++ with the Clang API
https://maskray.me/blog/2025-03-09-compiling-c++-with-clang-api
https://redd.it/1j7qhif
@r_cpp
"filesystem" was not declared in this scope
error: 'filesystem' was not declared in this scope; did you mean 'system'?
#include <iostream>
#include <filesystem>
#include <fstream>
int main() {
std::cout << "Current working directory: " << std::filesystem::current_path() << std::endl;
return 0;
}
I've tried adding `using namespace std` that didn't help either. I have g++ 13.2.0 and CLang 16.0.0.
iostream and fstream are working, filesystem is not.
Thank you in advance.
https://redd.it/1jbjjpn
@r_cpp
reconsidering COW , a modern c++20 string implementation
https://github.com/Mjz86/String_description/blob/main/README.txt
https://redd.it/1jbbheb
@r_cpp
what is the status of stoptoken in appleclang?
According to [cppreference](https://en.cppreference.com/w/cpp/compilersupport) it is implemented in clang, but not in applclang.
Does anyone have any idea when or if it will be merged to appleclang as well? the code is there, it just need to be pushed to the right repository.
I'm aware of Apple lack of interest in C++, that's why I'm asking.
https://redd.it/1jayj5q
@r_cpp
Usage of underscores in identifiers (in modern C++)
In one of my projects, I heavily use underscores in identifiers. None of the crazy stuff like "a leading underscore followed by a capital letter", that is so strongly reserved for the implementation. But many of my identifiers end with underscores or contain underscores in the middle.
Seems like every developer has a different opinion about this, and in every discussion, the holy ANSI-C standard is cited:
>The use of two underscores (`__') in identifiers is reserved for the compiler's internal use according to the ANSI-C standard.
However, ANSI-C defines also other restrictions, that seem a little bit outdated to me. In my project, I use C++20, soon switching to C++23; the code is C++-styled and not C-styled like in the glorious old days of programming...
Just wanted to hear your thoughts about the underscore topic. Do you use it? If not, are there reasonable points against it, nowadays?
https://redd.it/1jajhe0
@r_cpp
about the job posting
HI I want to apply for the certain jobs but doesn't how to do on the reddit
give me some ideas or eample so that I can do it
https://redd.it/1ja9lsx
@r_cpp
I though you all here would like this
std::min((objLeft - right), (objRight - left));
std::min((objTop - bottom), (objBottom - top));
std::min((objFront - back), (objBack - front));
It happened by chance. It's perfect.
https://redd.it/1j9z5sd
@r_cpp
Should I start with SDL2 or SDL3?
I want to try to get into game development with c++ or c and chose sdl as my library of choice (raylib was too annoying to setup). But with the new sdl3 release, im pretty confused if i should learn that or sdl2 since it's older and there's alot more resources out there that can help me learn.
https://redd.it/1j9bumg
@r_cpp
C++ vs Rust for fast Computer Vision/Deep Learning?
I want to make CV/DL related software that can be used in production. Microseconds matter. I know Rust well enough, but I don't know any C++. Everywhere people seem to say that C++ is obsolete and only used for existing projects, but I doubt it.
I'm also wondering about the factor of experience to speed. In Rust will it be easier to write fast code with less experience? Or is it possible to write just as fast or faster code in C++ with less experience?
I have seen things like TensorRT and OpenCV and Skia are C++, and while I could use Rust bindings, don't know if that's the best way. I am open to learning C++, as I believe it will make me a better programmer to have more experience with lower level concepts and obstacles. Thanks everyone.
https://redd.it/1j930na
@r_cpp
C++ Skills to Land a Junior/Graduate Role
I really love working with C++, and my current aim is to get some experience with it in a professional environment. I have a bachelors in computer science and am currently studying a computer games programming course. I have worked with Unreal Engine but have worked on both console applications and a game using C++ frameworks.
I am currently finding the games job market difficult, and would love to expand my skill set to land some kind of C++ role.
Any advice?
Edit: When I wrote skills I initially thought of libraries. But if anyone has anything else that's relevant to suggest, please do
https://redd.it/1j8s4aa
@r_cpp
Why P2786 was adopted instead of P1144? I thought ISO is about "standardising existing practice"?
I've found out in https://herbsutter.com/2025/02/17/trip-report-february-2025-iso-c-standards-meeting-hagenberg-austria/ that trivial relocatability was adopted.
There's whole KDAB blog series about trivial relocatability (part 5): https://www.kdab.com/qt-and-trivial-relocation-part-5/
Their paper P3236 argued that P1144 is what Abseil, AMC, BSL, Folly, HPX, Parlay, Qt already uses.
So, why in the end P2786 was adopted instead of P1144? What there the arguments to introduce something "new", resulting in, quoting blog:
>After some analysis, it turned out that P2786's design is limiting and not user-friendly, to the point that there have been serious concerns that existing libraries may not make use of it at all.
Thanks.
https://redd.it/1j8p9da
@r_cpp
After 9 hours i discovered how to import an library 🥳🎉
I MANAGE TO IMPORT RAYLIB!!!
I DONT CARE IF YOU THINK I AM AN BABY, THIS WAS THE BEST HIGH ON PROGRAMING OF THE YEAR
I decided to learn c++ because i want to fix an annoying bug in Godot, thats being an problem in my game, but man, i was humbled today, but i did it!
for some reason MSYS on windows have 5 editions, and i was using the wrong one :P
also, can some one explain why thats?
https://redd.it/1j8akpp
@r_cpp
I'm learning C++
Hi all. I'm only posting this for accountability. I'm learning C++, starting learncpp.com.
I'm an artist, I've always drawn, painted, I've 3D modeled, and I also like making music, and I also like literature, science, technology. I'm 27 years old and I was debating what I'd do for a living, what will I commit to?
And then I realized, making videogames allows me to combine all the things I love. Though in practice, it may not be that simple, at least as an indie game developer I can sort of do this. I can create art, I can write, make music... I don't know.
I always had this dream of making videogames and uyears ago I was teaching myself so I have a good idea of what to do to begin learning again (from learning a programming language to the game engine, etc.).
I'm not projecting any serious success any time soon, but I figured it's time to commit to something I love, and when I coded back then when I was learning, I actually enjoyed solving my problems, though I think it was C# I was working with.
Anyways, I just wanted to share this. I will share progress when the time comes.
If anyone has any resources, they're very welcome. I found some books, Youtube channels, and even courses on Udemy that seem interesting.
https://redd.it/1j85fs6
@r_cpp
Is Winlibs safe for minGW?
I am wondering if downloading it safe or not,
And is there alternatives except -visual studio- it's heavy on my machine?
https://redd.it/1j7y2v9
@r_cpp
C++ modules and forward declarations
https://adbuehl.wordpress.com/2025/03/10/c-modules-and-forward-declarations/
https://redd.it/1j7ue8o
@r_cpp
feedback about library
For the last two years, I've felt like I'm stuck in Groundhog Day with my career, so much so that looking at code sometimes made me want to puke. A friend pushed me to start a pet project to beak out of the funk, and what started as a little experiment turned into a library.
This is my first real dive into the world of templates, and honestly, I'm still not sure about some design choices. I'd really appreciate any type of feedback you can throw my way.
A bit of context, it's a color conversion library build around a simple API, and its modular so you can build and link the parts you need. There is still stuff i want to add but this feels like the right time to see how its turning out it gets bloated.
https://github.com/neg-c/psm
https://redd.it/1j7luu3
@r_cpp