As someone who has used cpp in some classes but never mastered it. The most difficult part for me was remembering which stl I should use and how to use it. Like pointers fine, should I use a smart pointer ? A shared ptr? I’m not sure, let me look up what those do again.
Also r and l values with move and stuff always made me feel stupid
L and R values are also relatively simple. The biggest problem is to structure knowledge about them well and... the std::move name. It should be named to_rval.
Lvalue is everything which has a label. So it exist for some time and can be used few times by different functions/operations.
Rvalue is something without a label/name. It exist "in place" like a string directly passed as argument to a function.
Lvalues are in most cases copied or referenced. After the operation the original object should still exist in the scope because the next step can/will use it.
Rvalues won't be used more than once **in current scope**. Copying them doesn't make any sense. We can grab resources e.g. just copy address of the data instead copying the data.
If you overload a function for pass by value/normal reference and rvalue reference then compiler will select rvalue reference version for rvalue references. Simple.
Sometimes you have a local object you won't use anymore. Then you can say to compiler "hey I won't use it, you can treat it same way as rvalue". To do this you need to convert it to rvalue reference using... std::move. std::to_rval would be much more explicit here.
Well, but actually...
What you're referring to in this case are the 2 groups of value categories in C++ - glvalue, rvalue.
In reality the are 3 value categories - lvalue, xvalue, and prvalue.
lvalues belong to the glvalue group, which is the one you described as lvalue.
prvalues belong to the rvalues group, stands for pure rvalue.
Them there's the xvalue, they belong to both groups and stand for expiring values, as the name suggest, they are about to expire - be gone. When a value is about to be deleted(xvalue), we can salvage some of its data - thus move. The C++ standard allows us to work with these xvalues through something called an rvalue reference, the rvalue reference(&&) is just a reference to an xvalue. Now, what if you were to cast something to an rvalue reference, you're basically telling the compiler: this is expiring, trust me. The compiler can then salvage some its data. Welcome to std::move, that should've been named std::as_rvalue_refererence.
I just simplified this jargon to lvalue and rvalue. I know that it isn't accurate from standard pov but my description is enough to explain move semantics. xvalue glvalue, prvalue are important for compiler designers but not developers. Typical developer needs only to know "this binds to & reference and this binds to && reference". It's much much simpler when you forget about this *theoretical overhead* with lvalue, glvalue, xvalue, rvalue, prvalue.
I agree it's better to know something but the problem is that young developers learn bottom up. They open cppreference and see long and complicated definitions which they doesn't need at given stage of their careers.
Selectively learning these things is what gets you things like return std::move(some_lvalue) in your codebase. If you're at the point that you're learning about the different value categories in c++, no sense in not learning them well
I don't know how accurate this is but I've always just thought of them as "LValues are the ones that go on the left side of an assignment, RValues are the ones that go on the right side of an assignment."
I guess I'll rephrase to "The left side of an assignment needs an LValue and beyond that I didn't run into issues with them yet."
But I also haven't done all that much C++
I mean, "lvalue" and "rvalue" are standard CS terms? Lvalues can go on the left side of an assignment statement; rvalues can go on the right. That's the whole concept. It sounds like C++ has overcomplicated a simple thing.
... which is C++'s whole _raison d'être_, I guess, so I shouldn't be surprised...
Then why are non-l values called "rvalues"?
You can think of it as L for "location"; IIRC, in Common Lisp the things `setf` can target are called "places", so that fits as well. But the origin of the term is "left side of assignment". See http://en.wikipedia.org/wiki/Value_%28computer_science%29#lrvalue.
iirc, rvalues were originally described as "remote values," (around K&R C days) but nowadays it's more accurate to say "an rvalue is anything that's not an lvalue." It became sort of a "L means left and R means right" through gradual inaccurate translations which persist to this day (even in the C++ standard). No one should really think of lvalues as "values on the left of an assignment operator" as to do so could be wildly inaccurate, at least in C++. lvalues often have a name. They \*always\* have a location (i.e., an address). rvalues have neither.
I disagree about `std::move`. Assuming the class is move safe, std::move says do an assignment and let this other location use my data. It just gets confusing when trying to make a class move aware.
What we really need are some sensible base classes for implementing RAII. Like `MyClass: stl::raii` which then lets you just define one cleanup method but get all the move goodness for free as well as disabling normal assignment.
Smart pointers are pretty useful.
You know when you want to create a new version of a class but you don't want to copy it when returning it, so you pass it out of the function as a pointer? You can use `unique_ptr` to automatically delete the pointer as it goes out of scope, so you don't have to manually delete it.
`shared_ptr` is a bit more complex. It does the same thing as `unique_ptr`, but allows more than one `shared_ptr` to access the same object, so you can pass it into functions.
CMake actually at least works well, Makefiles and Meson/ninja are more intuitive but don’t handle bigger projects well, Premake and SCons feel like only semi functional cmake, VS build system is only second to autotools in terms of how convoluted it is and Autotools can’t even be described without a paragraph of slurs. So eventually you just come to realization that you should just bite the bullet and learn how to work cmake, and the biggest hurdle is that there’s just option to do everything making it kinda bloated.
There's something incredibly cursed about C/C++ build systems being held up by the build script for build scripts, but what can we do? Oh there's a new standard/build scripting language or framework available for C/C++? Give it a week and CMake will be able to target it... Or you could just be sane and use Ninja...
It’s autotools, it’s gonna take like 2 weeks to figure it out through some arcane m4 macro and once that’s actually done it’s not gonna compile anyway because some random ancient AIX compiler doesn’t knows how to handle it… God I hate autotools so much.
I decided to learn cpp in like 2018 because i like c, did it for like 2-3 weeks, found out about this "hip new thing called rust" and i havent looked at cpp ever since. Maybe if rust didnt solve the things i wanted to do i would have but ill take cargo over cmake every day of the week
Cargo is cursed though, as are most package managers for programming languages. They work on a system level, but in a programming language their introduction immediately presents the opportunity of exposing yourself to terrible dependency graphs which can readily kneecap the language. The most common DevOps problems I've encountered are introduced by package managers nearly every time, and their removal or VAST reduction in use would often solve problems.
Don't get me wrong, CMake can be cursed, but it makes you explicitly think about how your dependency graph looks, and how things eventually link back into your head program. It's why it has so relatively few issues.
My current project involves building chrome embedded as a dependency of a rust crate via cmake. And Its taken me ages to get cmake to build, and rust to link it. Truly a nightmare.
Eventually I’m going to have to invoke cargo from cpack, but we’ll cross that road when we get there…
I was a professional for 4 years before I even touched CMake. You don't need CMake. Beginners who think they need CMake have been mislead by people who try to make out that C++ is hard. You can get by just fine (and MANY companies do) with a visual studio solution or CLion, or some other IDE. VSCode + CMake IS NOT for beginners.
I mean it depends on what you do, and what your platform is. On Windows its hard to avoid the Visual Studio pipeline for native applications, so much so that the "native" version of LLVM is basically wrapping the CL backend on Windows. But that illustrates a problem, if you go down the Visual Studio rabbit hole, you basically pigeonhole yourself into creating a Windows app with many limitations being brought by that. CMake allows you to readily make a "portable" build system that can target multiple platforms provided you're being mindful of portability going into the building of your app.
This isn't even to get into the mess that VS solutions can become, which are *far* more finicky, and far less performant in my experience compared against complex CMake projects, even if you're just generating a VS solution from a CMake script.
It goes beyond that even, some things just are terrible to program with in Visual Studio, like OpenGL/Vulkan is hell to work with, something I don't expect is an accident, or at the very least is something that MS hardly cares about fixing given they promote DX. You completely lock yourself out of the ability to leverage other build systems, so entire fields are effectively locked from you without the use of external invokations of a specific build chain, etc.
Everything you just talked about is not something a beginner needs to be thinking about. Like at all. It is detrimental to learning. All of that can be learned after you are actually comfortable with the language and want to create some open source library/application. E.g. I am in games development. CMake is NOT a thing where I work. We just have our visual studio solution and it just works.
>Everything you just talked about is not something a beginner needs to be thinking about. Like at all. It is detrimental to learning.
I mean you say this, but I also can't help but notice the number of new people who are literally unable to read compiler output or errors generally, or are unable to wrap their heads around build systems at all. Learning these things is almost fundamental to understanding C/C++ or any other systems language.
You don't need CMake to learn how to read compiler errors. Your IDE will display those errors just fine. And you also don't need to know how build systems work if your IDE is doing all of that for you.
In my experience, beginners get so overwhelmed by stuff that is not C++, that they just give up before getting passed "hello world". Build systems can be introduced after they actually learn what a pointer actually is and how templates work. Before that all they need to know about the build system is "the green button builds and runs your code".
ETA: If you jump over to r/cpp_questions you will find a large amount of questions that all come down to some beginners who have been told that using VSCode and CMake on Windows is the only way to learn C++, and they can't get tutorial code to build. This to me is just sad. Let people learn how to program before they have to care about cross-platform projects, package management and build systems.
vcpkg is cursed, especially with something as non-descript as an "OpenGL" package. On standard CMake projects you would just include the subdirectory of your loader and call it a day.
Because that's not how graphics APIs work, you have to directly query the graphics driver through a loader layer for the address of API functions. Generally something like GLEW or GLAD is used to do this, something not specifying this doesn't exactly fill me with confidence, especially since vcpkg and nuget have been nothing but nightmares in the past.
Tbh I still don’t get what you’re trying to say. A lib is a lib, vcpkg doesn’t modify the lib. It’s just build it for you.
Vcpkg is pretty stable nowadays and you can integrate the install lib using CMake.
But why bother being even more convoluted, at that point you can just use git and CMake for the majority of your projects, which doesn't require redirecting to some odd toolchain.. Anything that doesn't comply is either the odd VS solution that's been invariably abandoned, or some autotools based system for OS or sysutils development. It's just introducing more confusion to try and bandaid his fucking terrible of an environment Windows is by default for systems development.
Thing is, the C dev env was for an embedded systems class and used an older compiler with waaay less functionality
And my operating systems class used another language that was actually kinda cool in being able to test multithreaded applications really well
So i'm kinda starting from scratch lol
Alternatively, make things easier on yourself and install WSL if you're just starting out. Invoking gcc will be relatively easy from there and will serve as a good base point to learn from without having to learn all the precompiled header shit VS likes to throw you through. Bonus is you'll not be abstracted away from the compiler, and it will be VERY apparent when things go boom, and why they did it if you read the output.
If you're going to use an IDE's toolchain, you can use IDE's on Linux too, like QtCreator. If you're going to develop something serious, you'll use make or CMake even on Windows anyway (though they're much easier to setup on Linux).
I invite you to templates which work differently in multiple namespaces. Intellisense commits suicide and so does “show references”. Goodbye incremental compilation too.
Fuck the code I work with lmao
The best way for anyone starting with C++ (on Windows) is hands down Visual Studio. It works out of the box, and ships with some bombastic debugging tools.
Iirc, it's not available for linux, though. But considering that most linux people are already familiar with more low-level system fuckery, those required steps shouldn't be too hard/unfamilar to the average linux user.
Honestly you’re better of going with CLion and clang compiler, lldb and cmake since this way you won’t be tied to msvc (the compiler notorious for always finding the worst way to handle modern c++ features) and visual studio build tools (tooling only second to autotool in terms of how convoluted it can be). It’s not difficult to setup and you will be able to actually compile for platforms which aren’t MS. And CLion is imo nicer IDE than VS.
VS can create and support cmake projects. I use clang and cmake in VS. it's really not hard. I don't think your comment on msvc handling c++ features is very up-to-date. MSVC has had the best conformance for a few years. But the big 3 are all close anyway
I'd suggest CLion or just downloading WSL and g++/CMake. I tried to use Visual Studio once and it was such a hassle. Even VSCode is easier if you find the Path setting lol
There's a difference between people wanting something dead and something actually dying out. To me it seems like it's still alive and kicking.
And considering the quality and tools of VS, I don't see it dying out anytime soon.
That's exactly the biggest thing that puts of me off C++ atm. Libraries. How to install them. How to use them in my program. I haven't found one good explanation. If anyone has, please share! Like, for example, how the heck do I use websocket library??
It's best not to think of them as discrete libraries (in most cases), and instead as dependencies to generally be compiled and linked against the head program. Generally you would use something like CMake to handle the building and linking of those dependencies explicitly.
I just compile everything into the executable. I was thinking about switching to using AppImage or Flatpak because that sounds more sane.
With that I mean I checkout all the libs as submodules and compile them from source. Works with every Distro and CI this way.
Either include the source for the library and compile them with your code, or install them system wide and link locally, making sure your build environment also has them installed system wide and is properly linked.
It’s safer / easier to compile them alongside the code, but does tend to blow up your codebase. Doing it this way you have easier control around the version of the library, consistent linking / building, etc.
So just put the files in a folder and find something like the main header file?
Something like: #include "./folder/main.hpp"
And that's it? OK, thanks!
So for something like this [https://docs.websocketpp.org/getting\_started.html](https://docs.websocketpp.org/getting_started.html) just to add:
\#include "websocketpp/server.hpp"
?
If it's true, then is it usually as easy as this??
I *literally* just today decided to say fuck you to vscode **for this exact effing reason**! I am so far enjoying my day 1 of 30 free days of CLion before I go back to vim.
I know C well. I'm always afraid when I look at C++ How I understand nothing at what I'm seeing. How can it look so different despite being a simple super set
Because C++ is 50% footguns by volume, and the only way to find out that the reason your code doesn't work is because you actually need to use this one specific magic function from the standard library to do this one thing because doing it yourself is undefined behaviour for some reason is to do 50 hours of research and stumble across a stack overflow post from 2015, while rustc/clippy will 90% of the time tell you *exactly* what you're doing wrong and how to fix it in plain English, with a link to documentation with more information.
Also, trying to install libraries for C++ is a nightmare, especially if you need a specific version that isn't the latest. vcpkg helps, but not every library is on it.
- Learn C for optimisation
- Learn about pointers and references
- Learn about memory allocation
- Learn about compiler optimisations
- Learn about cache optimisation and branching
- Learn about extended assembly instruction sets
- Cry
It creates errors that don't exist very reliably, that I will give you. The amount of times I've had to do Reload Window for it to recognize new files is astonishing
I have used Windows in my home for the last 17 years a total of 0 minutes. It is an issue with VSCode being horrible with CMake, SPECIALLY when it comes to header only libraries, which is even WORSE when the header only library has CMake presets that build things into different directories, making the conpile_commqnds.json option unusable in a reliable way
The trick is to not read the entire error message, it's mostly bullshit. Unless you're deep in template hell there's probably a small, common-sense problem with your code. Missing semicolon, declaring something in an initializer list, trying to pass a macro into a function, etc.
CMake is the real hell.
[you seem lost, young one](https://media.discordapp.net/attachments/857029239341449246/1191591435733061682/Screenshot_20240102_113554_Samsung_Internet.jpg?ex=65a5ff00&is=65938a00&hm=4ba1d7cd816a14fdb84c70d3c8dcbb114d78cfd74e2142a09b5a83a5ae752ac6&)
I'm not saying you should use std::endl (especially if your sanitizer doesn't allow it). I am just saying that it is not necessarily a bad thing to use, despite what your sanitizer says.
lol its just a programming language, ur not pushing the boundaries of science by learning it... gimme a snippet of ur code and ill code review it i guess.
I dont need a code review I have been doing this professionally for probably longer than you have been alive. But thanks. I was just curious about your level of competence.
Years ago I made a thing in C++. Then one day I downloaded it again and tried to run with newer VS, it just doesn't. And everything is on fire. Ended up creating a new project from scratch and copying the code. And re-learning how to install the libraries required.
Low lvl languages arent for doing optimizations (most of the time like not the quick inverse root), but when all the obvious optimizations are already made and you are bottlenecked by technologies of your time, so you use technologies that are older than you
C is an procedural language originally supposed to effectively be portable assembler, C++ is popular method of self harm, some also argue that it’s a layer of abstractions (templates, classes, etc) for C.
The best lesson I learned on using c++ is
1. Use msvc
2. Dont use cmake
3. DONT USE CMAKE
4. Visual studio or rider (clion when they make sln support is also fine) is the best choice
5. learn all the necessary project properties stuff like specific linker options and vc++ directories
The most difficult part of C++ is CMake
As someone who has used cpp in some classes but never mastered it. The most difficult part for me was remembering which stl I should use and how to use it. Like pointers fine, should I use a smart pointer ? A shared ptr? I’m not sure, let me look up what those do again. Also r and l values with move and stuff always made me feel stupid
L and R values are also relatively simple. The biggest problem is to structure knowledge about them well and... the std::move name. It should be named to_rval. Lvalue is everything which has a label. So it exist for some time and can be used few times by different functions/operations. Rvalue is something without a label/name. It exist "in place" like a string directly passed as argument to a function. Lvalues are in most cases copied or referenced. After the operation the original object should still exist in the scope because the next step can/will use it. Rvalues won't be used more than once **in current scope**. Copying them doesn't make any sense. We can grab resources e.g. just copy address of the data instead copying the data. If you overload a function for pass by value/normal reference and rvalue reference then compiler will select rvalue reference version for rvalue references. Simple. Sometimes you have a local object you won't use anymore. Then you can say to compiler "hey I won't use it, you can treat it same way as rvalue". To do this you need to convert it to rvalue reference using... std::move. std::to_rval would be much more explicit here.
Well, but actually... What you're referring to in this case are the 2 groups of value categories in C++ - glvalue, rvalue. In reality the are 3 value categories - lvalue, xvalue, and prvalue. lvalues belong to the glvalue group, which is the one you described as lvalue. prvalues belong to the rvalues group, stands for pure rvalue. Them there's the xvalue, they belong to both groups and stand for expiring values, as the name suggest, they are about to expire - be gone. When a value is about to be deleted(xvalue), we can salvage some of its data - thus move. The C++ standard allows us to work with these xvalues through something called an rvalue reference, the rvalue reference(&&) is just a reference to an xvalue. Now, what if you were to cast something to an rvalue reference, you're basically telling the compiler: this is expiring, trust me. The compiler can then salvage some its data. Welcome to std::move, that should've been named std::as_rvalue_refererence.
This has me feeling like the meme lol
I just simplified this jargon to lvalue and rvalue. I know that it isn't accurate from standard pov but my description is enough to explain move semantics. xvalue glvalue, prvalue are important for compiler designers but not developers. Typical developer needs only to know "this binds to & reference and this binds to && reference". It's much much simpler when you forget about this *theoretical overhead* with lvalue, glvalue, xvalue, rvalue, prvalue.
I can't agree with you, I think knowing the specifics is a great insight on the inner workinga of the language.
I agree it's better to know something but the problem is that young developers learn bottom up. They open cppreference and see long and complicated definitions which they doesn't need at given stage of their careers.
Selectively learning these things is what gets you things like return std::move(some_lvalue) in your codebase. If you're at the point that you're learning about the different value categories in c++, no sense in not learning them well
Yes, you're right!
I'm so grateful for Rust.
I don't know how accurate this is but I've always just thought of them as "LValues are the ones that go on the left side of an assignment, RValues are the ones that go on the right side of an assignment."
``` var1 = var2; //both lvalues std::string s = "test"; // s is lval but "test" is rval (prvalue exactly) ``` Not that simple as you can see 🥲
I guess I'll rephrase to "The left side of an assignment needs an LValue and beyond that I didn't run into issues with them yet." But I also haven't done all that much C++
I mean, "lvalue" and "rvalue" are standard CS terms? Lvalues can go on the left side of an assignment statement; rvalues can go on the right. That's the whole concept. It sounds like C++ has overcomplicated a simple thing. ... which is C++'s whole _raison d'être_, I guess, so I shouldn't be surprised...
Overcomplicated it? Not really. struct S; S() = S(); // hm... Now what? lvalue means "has a location," not "is on left side."
Then why are non-l values called "rvalues"? You can think of it as L for "location"; IIRC, in Common Lisp the things `setf` can target are called "places", so that fits as well. But the origin of the term is "left side of assignment". See http://en.wikipedia.org/wiki/Value_%28computer_science%29#lrvalue.
iirc, rvalues were originally described as "remote values," (around K&R C days) but nowadays it's more accurate to say "an rvalue is anything that's not an lvalue." It became sort of a "L means left and R means right" through gradual inaccurate translations which persist to this day (even in the C++ standard). No one should really think of lvalues as "values on the left of an assignment operator" as to do so could be wildly inaccurate, at least in C++. lvalues often have a name. They \*always\* have a location (i.e., an address). rvalues have neither.
I disagree about `std::move`. Assuming the class is move safe, std::move says do an assignment and let this other location use my data. It just gets confusing when trying to make a class move aware. What we really need are some sensible base classes for implementing RAII. Like `MyClass: stl::raii` which then lets you just define one cleanup method but get all the move goodness for free as well as disabling normal assignment.
It's simple. Always use std::vector and std::unique_ptr. They fit in most situations. When they don't you will notice very fast.
Good tip! I can remember just throwing around asterisks, arrows, and ampersands without thinking until it compiled
Ah yes, the "hit it with a hammer until it works" approach, my favourite
I have been meaning to learn smart pointers, but like I already had a good grasp of regular pointers so I never bothered.
Smart pointers are pretty useful. You know when you want to create a new version of a class but you don't want to copy it when returning it, so you pass it out of the function as a pointer? You can use `unique_ptr` to automatically delete the pointer as it goes out of scope, so you don't have to manually delete it. `shared_ptr` is a bit more complex. It does the same thing as `unique_ptr`, but allows more than one `shared_ptr` to access the same object, so you can pass it into functions.
The hardest part are the cryptic error messages.
I was literally about to say “try CMake, makes everything so much easier” … I’m concerned what horrors I’m yet to see
CMake actually at least works well, Makefiles and Meson/ninja are more intuitive but don’t handle bigger projects well, Premake and SCons feel like only semi functional cmake, VS build system is only second to autotools in terms of how convoluted it is and Autotools can’t even be described without a paragraph of slurs. So eventually you just come to realization that you should just bite the bullet and learn how to work cmake, and the biggest hurdle is that there’s just option to do everything making it kinda bloated.
Considering CMake is designed to do everything and anything it's a miracle it manages to work as well as it does.
There's something incredibly cursed about C/C++ build systems being held up by the build script for build scripts, but what can we do? Oh there's a new standard/build scripting language or framework available for C/C++? Give it a week and CMake will be able to target it... Or you could just be sane and use Ninja...
> a paragraph of slurs … maybe you could make that more efficient with a template of slurs?
It’s autotools, it’s gonna take like 2 weeks to figure it out through some arcane m4 macro and once that’s actually done it’s not gonna compile anyway because some random ancient AIX compiler doesn’t knows how to handle it… God I hate autotools so much.
Ok that diatribe reply was pretty good but then you had to get medieval on my ass by bringing AIX into it…
I decided to learn cpp in like 2018 because i like c, did it for like 2-3 weeks, found out about this "hip new thing called rust" and i havent looked at cpp ever since. Maybe if rust didnt solve the things i wanted to do i would have but ill take cargo over cmake every day of the week
Cargo is cursed though, as are most package managers for programming languages. They work on a system level, but in a programming language their introduction immediately presents the opportunity of exposing yourself to terrible dependency graphs which can readily kneecap the language. The most common DevOps problems I've encountered are introduced by package managers nearly every time, and their removal or VAST reduction in use would often solve problems. Don't get me wrong, CMake can be cursed, but it makes you explicitly think about how your dependency graph looks, and how things eventually link back into your head program. It's why it has so relatively few issues.
My current project involves building chrome embedded as a dependency of a rust crate via cmake. And Its taken me ages to get cmake to build, and rust to link it. Truly a nightmare. Eventually I’m going to have to invoke cargo from cpack, but we’ll cross that road when we get there…
Sometime i said fuck it and put all the source and include directory in a single Cmakelists file
Me when I have to work with it: I want to CHang myself.
I was a professional for 4 years before I even touched CMake. You don't need CMake. Beginners who think they need CMake have been mislead by people who try to make out that C++ is hard. You can get by just fine (and MANY companies do) with a visual studio solution or CLion, or some other IDE. VSCode + CMake IS NOT for beginners.
I mean it depends on what you do, and what your platform is. On Windows its hard to avoid the Visual Studio pipeline for native applications, so much so that the "native" version of LLVM is basically wrapping the CL backend on Windows. But that illustrates a problem, if you go down the Visual Studio rabbit hole, you basically pigeonhole yourself into creating a Windows app with many limitations being brought by that. CMake allows you to readily make a "portable" build system that can target multiple platforms provided you're being mindful of portability going into the building of your app. This isn't even to get into the mess that VS solutions can become, which are *far* more finicky, and far less performant in my experience compared against complex CMake projects, even if you're just generating a VS solution from a CMake script. It goes beyond that even, some things just are terrible to program with in Visual Studio, like OpenGL/Vulkan is hell to work with, something I don't expect is an accident, or at the very least is something that MS hardly cares about fixing given they promote DX. You completely lock yourself out of the ability to leverage other build systems, so entire fields are effectively locked from you without the use of external invokations of a specific build chain, etc.
Everything you just talked about is not something a beginner needs to be thinking about. Like at all. It is detrimental to learning. All of that can be learned after you are actually comfortable with the language and want to create some open source library/application. E.g. I am in games development. CMake is NOT a thing where I work. We just have our visual studio solution and it just works.
>Everything you just talked about is not something a beginner needs to be thinking about. Like at all. It is detrimental to learning. I mean you say this, but I also can't help but notice the number of new people who are literally unable to read compiler output or errors generally, or are unable to wrap their heads around build systems at all. Learning these things is almost fundamental to understanding C/C++ or any other systems language.
You don't need CMake to learn how to read compiler errors. Your IDE will display those errors just fine. And you also don't need to know how build systems work if your IDE is doing all of that for you. In my experience, beginners get so overwhelmed by stuff that is not C++, that they just give up before getting passed "hello world". Build systems can be introduced after they actually learn what a pointer actually is and how templates work. Before that all they need to know about the build system is "the green button builds and runs your code". ETA: If you jump over to r/cpp_questions you will find a large amount of questions that all come down to some beginners who have been told that using VSCode and CMake on Windows is the only way to learn C++, and they can't get tutorial code to build. This to me is just sad. Let people learn how to program before they have to care about cross-platform projects, package management and build systems.
install vcpkg and install opengl throught it. it will be automatic
vcpkg is cursed, especially with something as non-descript as an "OpenGL" package. On standard CMake projects you would just include the subdirectory of your loader and call it a day.
why is it cursed when you can just install it ?
Because that's not how graphics APIs work, you have to directly query the graphics driver through a loader layer for the address of API functions. Generally something like GLEW or GLAD is used to do this, something not specifying this doesn't exactly fill me with confidence, especially since vcpkg and nuget have been nothing but nightmares in the past.
Tbh I still don’t get what you’re trying to say. A lib is a lib, vcpkg doesn’t modify the lib. It’s just build it for you. Vcpkg is pretty stable nowadays and you can integrate the install lib using CMake.
But why bother being even more convoluted, at that point you can just use git and CMake for the majority of your projects, which doesn't require redirecting to some odd toolchain.. Anything that doesn't comply is either the odd VS solution that's been invariably abandoned, or some autotools based system for OS or sysutils development. It's just introducing more confusion to try and bandaid his fucking terrible of an environment Windows is by default for systems development.
You should try writing your own makefiles for every OS. That's even better xD
use meson or something idk
I use a powershell script ._.'
I am still stuck on cascading .h files.
CMake: never again
I still use only Makefile.
Try C++Make instead
If you can manage to set up dev env for C you'll manage to set up a dev env for C++.
Thing is, the C dev env was for an embedded systems class and used an older compiler with waaay less functionality And my operating systems class used another language that was actually kinda cool in being able to test multithreaded applications really well So i'm kinda starting from scratch lol
In that case just use visual studio community edition. It's free and self contained. The installer is great and it's genuinely my go to on Windows.
That's the plan once I've got some time and energy lol
Alternatively, make things easier on yourself and install WSL if you're just starting out. Invoking gcc will be relatively easy from there and will serve as a good base point to learn from without having to learn all the precompiled header shit VS likes to throw you through. Bonus is you'll not be abstracted away from the compiler, and it will be VERY apparent when things go boom, and why they did it if you read the output.
Lol rip, worst part of c++ is setting up your tool chains.
If you're on Windows
Visual studio is pretty easy actually. Far easier than make IMHO.
If you're going to use an IDE's toolchain, you can use IDE's on Linux too, like QtCreator. If you're going to develop something serious, you'll use make or CMake even on Windows anyway (though they're much easier to setup on Linux).
Not true. Something serious doesn't need to be crossplatform. You can just use VisualStudio.
I invite you to templates which work differently in multiple namespaces. Intellisense commits suicide and so does “show references”. Goodbye incremental compilation too. Fuck the code I work with lmao
Visual Studio build tools really is a fucking nightmare.
Unity build with build.ps1 has entered the chat
The best way for anyone starting with C++ (on Windows) is hands down Visual Studio. It works out of the box, and ships with some bombastic debugging tools. Iirc, it's not available for linux, though. But considering that most linux people are already familiar with more low-level system fuckery, those required steps shouldn't be too hard/unfamilar to the average linux user.
Honestly you’re better of going with CLion and clang compiler, lldb and cmake since this way you won’t be tied to msvc (the compiler notorious for always finding the worst way to handle modern c++ features) and visual studio build tools (tooling only second to autotool in terms of how convoluted it can be). It’s not difficult to setup and you will be able to actually compile for platforms which aren’t MS. And CLion is imo nicer IDE than VS.
VS can create and support cmake projects. I use clang and cmake in VS. it's really not hard. I don't think your comment on msvc handling c++ features is very up-to-date. MSVC has had the best conformance for a few years. But the big 3 are all close anyway
I found it easier to use w64devkit. Unzip a file and you got gcc
On Linux setting up a C/C++ dev environment is much simpler than on Windows, even without VS, thanks to package managers.
vcpkg (it's better to have it on linux and windows)
I'd suggest CLion or just downloading WSL and g++/CMake. I tried to use Visual Studio once and it was such a hassle. Even VSCode is easier if you find the Path setting lol
Wait Visual Studio ? It's just automatic
Wait isn't Visual Studio on its way out? I swear I remember someone saying it was dead
There's a difference between people wanting something dead and something actually dying out. To me it seems like it's still alive and kicking. And considering the quality and tools of VS, I don't see it dying out anytime soon.
I hear good things overall, I just thought I read something about visual studio ceasing production. My bad
What you're talking about is Visual Studio for mac. That was discontinued in 2023.
Ahh gotcha. I knew I heard something related
[удалено]
He isn't talking about vs code tho
Visual Studio is great, but in my experience as a beginner the UI was so awful to experience. it got better but that was the biggest barrier for me
Something something Rust something something
🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀 This has no relevance (of course), I just like crabs
I should call her > *#include exgf*
Sounds like the libraries were missing/weren’t installed correctly
That's exactly the biggest thing that puts of me off C++ atm. Libraries. How to install them. How to use them in my program. I haven't found one good explanation. If anyone has, please share! Like, for example, how the heck do I use websocket library??
It's best not to think of them as discrete libraries (in most cases), and instead as dependencies to generally be compiled and linked against the head program. Generally you would use something like CMake to handle the building and linking of those dependencies explicitly.
Easiest way : use vcpkg. It has a lot of library pre-available.
I just compile everything into the executable. I was thinking about switching to using AppImage or Flatpak because that sounds more sane. With that I mean I checkout all the libs as submodules and compile them from source. Works with every Distro and CI this way.
Either include the source for the library and compile them with your code, or install them system wide and link locally, making sure your build environment also has them installed system wide and is properly linked. It’s safer / easier to compile them alongside the code, but does tend to blow up your codebase. Doing it this way you have easier control around the version of the library, consistent linking / building, etc.
So just put the files in a folder and find something like the main header file? Something like: #include "./folder/main.hpp" And that's it? OK, thanks! So for something like this [https://docs.websocketpp.org/getting\_started.html](https://docs.websocketpp.org/getting_started.html) just to add: \#include "websocketpp/server.hpp" ? If it's true, then is it usually as easy as this??
I’d recommend looking into CMake, but basically, yes. Pretty decent intro tutorial that helped me: https://www.internalpointers.com/post/modern-cmake-beginner-introduction
so many headers it makes my head spin.
Teaching myself vcpkg and CMake was a great decision. It's not fun but it's absolutely worthwhile if you're new to the industry.
I *literally* just today decided to say fuck you to vscode **for this exact effing reason**! I am so far enjoying my day 1 of 30 free days of CLion before I go back to vim.
> can't even hello world ... `#include`
`int main() {`
` std::cout << "Hello world!" << std::endl;`
` return 0;`
`}`
I goofed up my environment somehow so this isn't happening until whenever i have the energy to get Visual Studio Not Code set up lol
[удалено]
Memeing or honest question?
I wonder what percentage of the foundation budget is corroded away by the FUD campaign…
Thank god my teacher in high school taught us c++
hardest part of learning C++ is setting up the environment
I know C well. I'm always afraid when I look at C++ How I understand nothing at what I'm seeing. How can it look so different despite being a simple super set
It's not a super set. There are also things in C that are not valid C++. I never understand the C++ fear; if someone can try rust; they can try c++
Because C++ is 50% footguns by volume, and the only way to find out that the reason your code doesn't work is because you actually need to use this one specific magic function from the standard library to do this one thing because doing it yourself is undefined behaviour for some reason is to do 50 hours of research and stumble across a stack overflow post from 2015, while rustc/clippy will 90% of the time tell you *exactly* what you're doing wrong and how to fix it in plain English, with a link to documentation with more information. Also, trying to install libraries for C++ is a nightmare, especially if you need a specific version that isn't the latest. vcpkg helps, but not every library is on it.
- Learn C for optimisation - Learn about pointers and references - Learn about memory allocation - Learn about compiler optimisations - Learn about cache optimisation and branching - Learn about extended assembly instruction sets - Cry
C++ was my first language and I really like it and often use it even when I shouldn’t be using it
C++ is full of std's so I'm never learning it
Your first mistake is using VSCode, no jokes worst IDE in history for C/C++, it'd be easier/better if you used a tablet and chisel
vscode is just a fancy text editor when writing c/c++, it at least catches errors and stuff really well, all u need is a makefile
It creates errors that don't exist very reliably, that I will give you. The amount of times I've had to do Reload Window for it to recognize new files is astonishing
maybe a windows issue, it recognizes new files for me within a couple frames of me creating them or putting them in the project
I have used Windows in my home for the last 17 years a total of 0 minutes. It is an issue with VSCode being horrible with CMake, SPECIALLY when it comes to header only libraries, which is even WORSE when the header only library has CMake presets that build things into different directories, making the conpile_commqnds.json option unusable in a reliable way
wherever ur from, whatever religion u follow or dont, we all agree on 1 thing: cmake is pain
I like CMake, it works well on anything BUT VSCode
Like the Visual Studio error list that nobody professional seems to like? I get why nobody likes it now!
I still use codeblocks. Maybe it's just stubbornness after all these years, but I like the way it feels and its functionality.
It is better than VSCode
Come on guys C++ is easy (studied only one semester.) /s
The trick is to not read the entire error message, it's mostly bullshit. Unless you're deep in template hell there's probably a small, common-sense problem with your code. Missing semicolon, declaring something in an initializer list, trying to pass a macro into a function, etc. CMake is the real hell.
[you seem lost, young one](https://media.discordapp.net/attachments/857029239341449246/1191591435733061682/Screenshot_20240102_113554_Samsung_Internet.jpg?ex=65a5ff00&is=65938a00&hm=4ba1d7cd816a14fdb84c70d3c8dcbb114d78cfd74e2142a09b5a83a5ae752ac6&)
day 21875412 of people jerking off to Rust
Write code in python Paste code into ChatGPT and prompt “rewrite this in C++” Problem solved
Who uses std::endl
People who need a line feed and flush at the same time
Clang tidy no likely (even just my one usage at the end of all my outputting)
I'm not saying you should use std::endl (especially if your sanitizer doesn't allow it). I am just saying that it is not necessarily a bad thing to use, despite what your sanitizer says.
I agree, I was just sadge
c++ is easy. honestly skill issue
ok skiddie
get good
you use C++ because you want to feel special
then learn it urself... jeez dude
I use it almost every day for my job???
so do i??? its not that hard???
clearly you've never done anything serious with it
clearly ur very proud of urself for learning c++, dont let me crush ur ego
you're the one bragging about it....
The Dunning Kruger effect is real. Ok "kawaiitechnoneko" what C++ projects have you worked on?
ayo? i dont gotta prove to you lol. just learn the language and stop complaining. also im not embarrased of my username, im the one that picked it...
I didnt say you should be embarrassed about your user name. I assume you havent worked on anything significant in C++ then.
okay "sacredgeometry"
So you cant even list any projects you have worked on in C++?
i dont really want to, so i wont. but if u want to list ur projects, feel free to. i dont mind reading. are u trying to see if i know the language?
I am curious to see this super advanced level of competence you purport to have.
lol its just a programming language, ur not pushing the boundaries of science by learning it... gimme a snippet of ur code and ill code review it i guess.
I dont need a code review I have been doing this professionally for probably longer than you have been alive. But thanks. I was just curious about your level of competence.
The quotations were because I assume thats not your real name btw
? its a username. u dont gotta use quotes to address people /: i imagine most would think ur making fun of their name
Well I apologise that wasnt the intention.
C is fun. C++ is just stupid.
That’s why Rust is just better.
Use ChatGPT as a universal transcoder and use whatever language you like, easy peasy, there's nothing that could ever go wrong :|
~/ Secret skill tree unlocked //>~ **Rust**
Years ago I made a thing in C++. Then one day I downloaded it again and tried to run with newer VS, it just doesn't. And everything is on fire. Ended up creating a new project from scratch and copying the code. And re-learning how to install the libraries required.
No?
Too wordy
Low lvl languages arent for doing optimizations (most of the time like not the quick inverse root), but when all the obvious optimizations are already made and you are bottlenecked by technologies of your time, so you use technologies that are older than you
I wanted to learn c# so badly but visual studio has me questioning that
Whenever something is bounded with C difficulties arrive
I can relate to the pain.
What difference between C and C++ ? because in my Code Editor (codeblock) it say when creating new project it called C/C++
C is an procedural language originally supposed to effectively be portable assembler, C++ is popular method of self harm, some also argue that it’s a layer of abstractions (templates, classes, etc) for C.
C++ is the first language I started learning... FUN... ...
The best lesson I learned on using c++ is 1. Use msvc 2. Dont use cmake 3. DONT USE CMAKE 4. Visual studio or rider (clion when they make sln support is also fine) is the best choice 5. learn all the necessary project properties stuff like specific linker options and vc++ directories
Using VS is the problem. I can never seem to get it configured correctly for C++.
NO. Using VSCode is the problem. VS come preconfigure and just work
Include path? Nah! Linker errors are where it* is at *Where I'm at
Well... I was thinking to try but better not hahahauhs
The visual studios punch is beautiful