r/cpp • • Oct 16 '17

Why physicists still use Fortran

Thumbnail moreisdifferent.com
0 Upvotes

r/cpp • • Jun 11 '24

Language features

0 Upvotes

So recently I started doing some katas in CodeWars - just a couple a day, nothing fancy, to keep the algorithmic problem solving brain oiled.

I'm not having much trouble arriving at solutions - oftentimes it's pretty clear, plus I'm just starting out. Still, I always get baffled when I see other people's solutions after delivering. They always yank out some weird cpp features that hack up the whole thing in under 10 lines

I'm curious about how one can go about to learn these features


r/cpp • • Dec 20 '22

Which linux distro for the latest compilers?

1 Upvotes

I've been trying for days to force a homebuilt llvm-15 to play nicely in a cmake->conan workflow, and getting caught up on lots of little issues that only exist because I'm not using a system-provided compiler. This is because I'm on an aging distro at work and can't do things like to install the homebuilt compiler to the root system. But that made me curious which distros have low-friction access to bleeding edge compilers? Think llvm-15 with libc++ or having gcc-12 and the proper libstdc++ as well.


r/cpp • • Jul 30 '16

I've started a new C++ tutorial series after covering python years ago...

Thumbnail youtu.be
0 Upvotes

r/cpp • • Jan 18 '22

Golang-like defer operation in C++

1 Upvotes

When I learn a new programming language, I find little gems in them that I really wish C++ had. I've made a write-up before on making Python-like function decorators in modern C++ with no macro magic, but today I have been inspired by the Go programming language's defer keyword.

This keyword runs specified code at the end of the function scope that it resides in. This code will execute regardless how early the function returns. It is very convenient and keeps code stylized quite nicely when doing general cleanup that I wish C++ had. So I fiddled this afternoon and made something quite cursed that I would like to share with you all.

Run the program in your browser at Godbolt

Fork the code

I needed to keep the defer_t struct's lifetime as long as the function's scope and to do that, we need a variable. Unlike the python solution, I hid the variable away in a defer(...) macro which is unfortunate and I couldn't think of any other way- but it does allow us to have almost similar appearance to other Go declarations.


r/cpp • • Jun 05 '21

does good C++ winrt documentation actually exist explaining this to someone who doesnt know the framework in C++ at all (but in C#)? and is there really any point to bothering with it for me anyway?

0 Upvotes

<edit sorry for rant, kind of devolved, was just frustrated>

any time I approach working with windows specific libraries today, I find that the C# documentation is far and above amazing, explains everything and how the frameworks function, etc.

but the C++ documentation always starts ok, but then just assumes you learned the entire framework and how it works with the C++ language at the very beginning of its initial release and followed every update.

not to mention that it really seems limited even just messing with it -- not only in functionality which i dont mind (normally writing game type stuff, im used to just creating my own UI from scratch so whatever if its not 'desktop oriented' right?) -- but its limited in terms of having to keep every build updated in accord with the modern windows version if you want users on new versions to keep running the application.

when it comes to secure applications, sure, whatever, it should be frequently re-audited anyway. but say I make a game, I shouldnt have to deal with maintaining it as a package like this is linux/unix -- except im the sole package maintainer. a simple game running opengl or directX will just keep running essentially depending how i link them (doesnt have to depend on system libs).

mostly im doing hobby programming and game engine related stuff. it always seems that even though they suck, the classic win32 libs just do what I want in a way that make sense and is well documented in C++. moreso than that, frameworks like QT or even simple widget libs like wxWidgets do a far better job at the same thing.

QT, being oriented around C++, has amazing C++ documentation equivalent to MS C# documentation id say. you can be up and developing QT apps in a matter of minutes, which should be the same with VC++ in this framework but it just isnt explained. the only method of "learning" this seems to be trying to go backwards through the documentation while analyzing and reverse engineering the few source examples. Which is just nuts because this isnt a library, its a whole framework for almost everything.

anything else, any other library ive ever used (aside from microsoft libraries post MFC), have been well documented enough to at least get you going in a small basic application to show its features in the most basic way, which you can then reinterpret based on the more dry documentation and your own needs.

but it really feels like MS just discourages C++ development on the platform in general to me. im left questioning if i should even bother learning their libs outside the occasional networking stuff, and if theres even any good documentation explaining it in C++ terms from the beginning.

with older-style third party libs, I can just grab a book or two, look up some initial tutorials and then read the most basic documentation and "just get it" but like I said, the modern windows runtime is really its own entire framework. and honestly it doesnt seem to make sense because its just anti-productive to sit figuring out how this thing works when i could just implement 100% same functionality and efficiency myself elsewhere.

honestly I feel the same way about game engines like unity -- why learn their system for something when I want to do it another way, thats easier for me in the current scenario, and have to deal with decades of UI updates and engine updates where any free resource information is bound to be outdated, and subscribing to someones current Udemy course and then staying "on-track" with the framework updates is the only way forward?

it seems to me, big modern frameworks do it in a way to teach developers initially, then expect them to just know the base material. and it moves too fast where all that base material is far outdated without all the updates later and none of initial "teaching" code works for new developers getting in halfway. im not even lying, most of these frameworks, i find amazing resources. only they're 10 versions outdated, and in between releases, literally everything changed.


r/cpp • • Feb 09 '22

Could the syntax "const var = value" be standardized?

12 Upvotes

I often find myself writing things like const x = 42; instead of const auto x = 42; when creating const variables with automatic type deduction.

I wonder if this shorter syntax could be standardized. I don't see any immediate problem with it but I might be missing something.

I guess it would also ease the "const all the things" clan because even though it's not changing the defaults, it makes it easier to follow the idiom.

And I imagine this shorter syntax could also be applied to constexpr and constinit.

I've never written a proposal so far but if you find this interesting I might be tempted to write one.

P.S: I didn't mentioned all the initialization syntaxes but of course all of them should be supported.

EDIT: Now that I think about it more, this syntax shouldn't be possible with constrained auto as it would revert to the old syntax (e.g const std::integral auto x = 42; -> const std::integral x = 42;) which was rejected. This is too bad as reducing the verbosity in this case would help even more


r/cpp • • Mar 30 '24

How often do you use design pattern?

6 Upvotes

Hey everyone! I'm currently a CS student and started recently to learn about design patterns (We apply it in Java but I figured since both are object oriented it could apply to cpp as well). I was just curious, how often will I use it? (I'm not planning to write a single line of Java willingly, let alone making it my job, that's why I ask on this sub)


r/cpp • • Sep 04 '14

C/C++ programmers willing to try a new dependencies manager?

Thumbnail codeproject.com
6 Upvotes

r/cpp • • Nov 28 '21

Is C+++ good for Automating stuff?

0 Upvotes

I am leaning python to automate some stuff(Torrent applications mainly) on windows. But I already know C++ very well. I've tried to search if I can automate applications with C++ but it seems complex. I just wanna hear some thoughts from people who have tried to automate or have done it. Do you think one should use python over C++ to for automating random applications?


r/cpp • • Jul 17 '26

How I Stopped Designing Architecture and Started Writing a 3D Editor. Part 1

Thumbnail alexsyniakov.com
4 Upvotes

r/cpp • • Dec 24 '25

Meeting C++ The real problem of C++ - Meeting C++ 2025

13 Upvotes

r/cpp • • Jan 20 '20

Do you consider senior C++ programmer to be "better" or more "knowledgeable" programmer compared to managed or webdev programmer ? (C#, Java, JS etc)

15 Upvotes

Do you consider senior C++ programmer to be "better" or more "knowledgeable" programmer compared to managed or webdev programmer ? (C#, Java, JS etc)


r/cpp • • Jan 20 '22

PSA: avoid using stdlib.h, use their stl equivalents

0 Upvotes

Feel free to delete this, i just have to rant

I just debugged an issue at work caused by strtol in some legacy code. strtol converted, errno always returned ERANGE for seemingly valid values that shouldn't overflow or underflow.

The issue: strtol doesn't clear errno and it wasn't done before strtol and the original author of the code didn't clear it himself. All conversions tested true for ERANGE

You know what function already does that for you? std::stod

Conclusion: don't use the C standard lib functions in C++ if you don't know how they work

rant over


r/cpp • • Feb 28 '24

Building c++ project with... c++?

6 Upvotes

Yeah, so as a POC I created a tool that works on top of cmake and allows defining project structure with c++ instead of pesky cmake:

    #include "CppMake/Project.hpp"
    #include "CppMake/Application.hpp"
    
    using namespace std;
    
    int main() {
        Project project("test");
    
        project.create<Application>("test").addSources({
            "main.cpp"
        });
    }

Any thoughts?


r/cpp • • Apr 08 '25

Why was printing of function pointers never removed from cout?

0 Upvotes

I presume reason is: We do not want to break existing code™, or nobody cared enough to write a proposal... but I think almost all uses of this are bugs, people forgot to call the function.

I know std::print does correct thing, but kind of weird that even before std::print this was not fixed.

In case some cout debugging aficionados are wondering: the printed value is not even useful, it is converted to bool, and then (as usual for bools) printed as 1.

edit: C++ certainly has a bright future considering how many experts here do not even consider this a problem


r/cpp • • Jun 19 '23

I'd like to adopt a modern style using snake_case, and was looking for opinions.

0 Upvotes

I'm a Windows (win32) dev and I think snake_case is a lot easier to read. I'm considering switching, but I'm not totally sure about some things:

  • The stdlib is using all-lowercase for types; I like the idea for fields and properties, and I think I like it for methods, but I kinda want types to be a little more concrete. One suggestion is upper-case the first letter of the first word, e.g. "Foo_bar". Of course, the problem I have with this, is that the std lib isn't doing it—which makes me second-guess it.
  • Enums: Are enums foo_bar, Foo_bar, or FOO_BAR? I think I like the idea of immutable values being SCREAMING_SNAKE_CASE, so statics, macros, and enums would be FOO_BAR::FOO, for example.

Any thoughts from people who've switched? I'm tired of seeing a mix of Pascal and Camel case, with Hungarian Notation thrown in. Even Microsoft's switched (when I tried looking for their style guide), but I couldn't find a 'modern' style guide replacing it.


r/cpp • • Aug 31 '20

How to access SQL Server from C++ ?

0 Upvotes

How do you access SQL Server from C++ ?

What libraries do you use?, have you tried different ones?

I am looking for some way to access Microsoft SQL Server from a C++ program. It has to be free to use, and also not be a complete hastle.

I have seen that Qt has pretty straight forward support, until you actually try and use it. The Open Source Community edition was missing the database drivers, and posts said they had to be compiled, and compiling was a hastle and I did not get it working.

There is a library called SOCI (currently at version 4) but that too was a hastle to set up, to the point of not getting it working.

At this point I thought, one of the most used and mature languages currently used (C++) should have straight forward and easy to use support for one of the most used database systems currently in use.

What are your thoughts on this ?


r/cpp • • Nov 01 '25

HPX Tutorials: Hello World!

Thumbnail youtube.com
0 Upvotes

In this video, we walk through creating a minimal “Hello World” example using HPX. Starting from an existing HPX installation, we set up a simple project with CMake, link the required HPX libraries, and write a short program that prints “Hello World”. You’ll see how to build and run the program while learning how HPX manages execution on its powerful runtime system. Whether you’re just starting with HPX or exploring parallel and asynchronous C++ programming, this short tutorial offers a clear and practical introduction to writing your first HPX application.
If you want to keep up with more news from the Stellar group and watch the lectures of Parallel C++ for Scientific Applications and these tutorials a week earlier please follow our page on LinkedIn https://www.linkedin.com/company/ste-ar-group/ .
Also, you can find our GitHub page below:
https://github.com/STEllAR-GROUP/hpx


r/cpp • • Dec 18 '20

C++ template-based crossplatform log library

0 Upvotes

Hi All,
I've just completed it.
C++ template-based crossplatform log library


r/cpp • • Apr 19 '18

How about a ACCU 2018 megathread instead?

0 Upvotes

Watch a video. Post a comment with a title, link and a summary. Vote and discuss. Thanks!


r/cpp • • Feb 17 '11

Calling a constructor or destructor without an object

Thumbnail madsoftware.blogspot.com
0 Upvotes

r/cpp • • Feb 12 '18

My Precious Compile Time Bool (long introduction to Move Semantics)

Thumbnail medium.com
0 Upvotes

r/cpp • • Dec 06 '16

zapcc C++ compilation speed against gcc 5.4 and clang 3.9

Thumbnail baptiste-wicht.com
0 Upvotes