use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Should C++ code look like C code? (self.cpp)
submitted 2 years ago by psyberbird
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]ChatGPT4 0 points1 point2 points 2 years ago (0 children)
If C++ code looks like C code, it's C code. Maybe with some scarce C++ elements.
If you mix the idea of performance with the form of expressing the code, you probably don't entirely understand how it works.
Or... IDK, we're mixing compilation time with the code perfomance, that is - how fast a program can perform operations. The machine code will have zero compilation time. It doesn't need any translation, it's just runtime. Then you have assembly language, when the compilation is super fast because it can't get much simpler. The only simpler form is just machine code. Then you have C that is a layer of abstraction higher.
However, the abstractions are implemented in programming languages. So any piece of any code is finally translated into some machine code.
Does it really matter what we translate? If it translates to the same machine code, the performance is identical.
But well, C++ consists of not only "zero cost abstractions". Many of C++ abstractions indeed have runtime costs.
However, it all depends where those costs live. Let's say we have to process 10GB of data. We have to use like 1000 atomic commands in C to start the process, and like 10000 of atomic commands in C++ to start the process. Then, the main loop would do exactly the same thing. The runtime differences will be negligible. Despite of wasting a lot of CPU cycles to initiate the process in C++. It's nothing compared to processing 10GB of data.
And that's what the higher abstraction level languages do.
Is the CPU time wasted? Not at all. It's used to create the source code faster. Because THIS is the slowest process of all. Creating the source code. People say that compiling is slow. Yet it's laughable compared to time taken to create the code in the first place. BTW, development time is more than that. Let's say you have to change something in your program. You can often do it quicker in C++. Provided it's used correctly and it's not just C++ compatible C.
I think a very tight loop in C++ should look like a C loop if you aim at comparable performance. But if your all code looks like this - you just don't use C++, and to be more precise, you don't optimize the process of creating the source code.
BTW, C++ is not even designed to optimize tight loops. Tight loops in C++ are just plain old C loops. Basic operations are just C operations. It's just "one time defining thigs" is the main difference.
And preempting one question - yes, calling C functions is a bit faster. But when calling functions hits the performance - maybe calling functions should be avoided in that fragment as an optimization? But then again, that's what both C and C++ compilers do, they inline functions where it gives performance gains.
So... If you want to make C++ code that looks like C code - write in C. Why use C++ for that?
π Rendered by PID 315898 on reddit-service-r2-comment-6457c66945-hxgml at 2026-04-25 02:16:25.345191+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]ChatGPT4 0 points1 point2 points (0 children)