C++ - Reddit
228 subscribers
48 photos
8 videos
25.3K links
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
Download Telegram
Understanding C++ File Extensions and the GCC Compilation Process

**Different C++ File Extensions**: In C++, you can use various file extensions like .cc, .cp, .cxx, .cpp, .c++, and .c. 

 **GCC: The Versatile Compiler**: GCC can handle all these extensions easily. 

 **Converting .cpp Files**:

* **Preprocessing**: Turn .cpp files into .ii files to get better debugging information.
* **Assembly**: Change .cpp files into .s files to see the low-level code.
* **Object Code**: Compile .cpp files into .o files to prepare for making an executable. 

 **Important GCC Options**:

* **-E**: Preprocess only.
* **-S**: Compile to assembly code.
* **-c**: Compile to object code.

For example: 

// Compile the code to executable:
g++ prog1.cpp -o prog1

// Generate preprocessed CPP program:
g++ -E prog1.cpp -o prog1.ii

// Generate assembly code:
g++ -S prog1.cpp -o prog1.s

// Compile preprocessed code to object file:
g++ -c prog1.ii -o prog1.o

// Alternatively, compile directly from source to object file:
g++ -c prog1.cpp -o prog1.o

 **Building a Command**:

g++ [options] [source files] [object files] [libraries] -o output_file

 **Why Learn This?** Knowing these details makes you more efficient in developing and debugging C++ programs. It’s especially useful for senior software engineers who want to write better, optimized code.

 #SoftwareEngineering #CPP #GCC #Programming #CodeOptimization #Debugging #CompilerOptions #CodingTips



https://redd.it/1djek8r
@r_cpp
Bolting on serializable, inspectable, precondition checkable, stack allocated coroutines onto CPP.

I am DSL designer in academia, a few years ago we identified a coroutine use case that required serializable, inspectable, precondition checkable and stack allocated coroutines in CPP. Instead of attempting the standardization process for cpp which would have taken took too much time and potentially lead nowhere, we decided implement the features as standalone cpp interoperable DSL (we have the same ABI as C) in the hope that if the DSL is interesting, then the ideas would spread to other languages. As far as we are aware, the mix of coroutine features we have is compleatly unique, and they enable one-click testing, automatic remote execution, automatic tracing and more.

language doc

cool example about preconditions in coroutines

Beside showcasing the language, this thread is mostly about collecting feedback about the article, in particular one example where we show case how people must write cpp today, and what precondition checkable, inspectable and serializable coroutines enable. The example describes the requirements of a problem as simple as rolling a dice twice in a video game, shows how you are forced to write cpp and how you could write it if you had serializable, inspectable and precondition checkablee coroutines. As far as I can think the statement is correct, the implementation in the link is pretty much the best possible cpp implementation, even macro tricks would not really improve the situation. Is there any way i can make the cpp example shorter, better and/or a fairer comparison?

https://redd.it/1ksachf
@r_cpp
C++26 ends a 40-year footgun

Reading an uninitialized variable has been undefined behavior in C++ for 40 years -- the kind optimizers exploit into real bugs. C++26 (P2795) reclassifies it as erroneous behavior: still a bug, still warned about, but defined, bounded, and not exploitable.

The demo poisons the stack, then reads an uninitialized int. As C++23 it prints garbage; as C++26, the same code prints a defined 0, every run. Live in your browser.

And [[indeterminate\]\] lets you opt back out when you really want an uninitialized buffer -- on purpose this time.

Read it: https://wrocpp.github.io/posts/erroneous-behavior/?utm_source=reddit&utm_medium=social&utm_campaign=post-erroneous-behavior

\#cpp #cplusplus #cpp26 #safety #programming

https://redd.it/1uo5y63
@r_cpp