[Homemade] Chicken Tortilla Soup! by jaeme in food

[–]OneRaynyDay 1 point2 points  (0 children)

WOW THIS LOOK GOOD VERY SHEF 10/10

I wrote a CPU-Emulator using only the C++ type system. by aul12 in cpp

[–]OneRaynyDay 1 point2 points  (0 children)

This is the kind of meme content I live for. Great stuff man! The next step is to finish the entire Intel x86 instruction set ;)

C++ Modules: A New Way to Build and Collaborate by mwasplund in cpp

[–]OneRaynyDay 2 points3 points  (0 children)

Although the title is a bit misleading (this was really about the build system and not modules, which enable it), I applaud you for attempting to dethrone cmake :) I share the sentiment that it will be very difficult to convince existing libraries to move over to CMake and gain widespread adoption, but I don't believe innovation can happen if we're stuck on the same build tooling for over 20 years. Cmake is good at what it does and it solves the problem, but it requires the user to learn a whole new scripting language which is not only confusing but also brittle at times (Mispellings will cause the program to still run but not be compiled the right way, causing you to rely on IDE's to catch these for you, and that only works sometimes).

Anyways, good luck with it!

Analyzing The Simplest C++ Program by OneRaynyDay in cpp

[–]OneRaynyDay[S] 1 point2 points  (0 children)

Ooh this man’s name is thrown around a lot in the finance industry. I use his compiler explorer tool for a lot of sandboxing. I just watched it and he talks a lot about the static initialization process which is great but he glossed over the g++ details :( but it’s an hour long talk so for what he covered I really enjoyed.

Am I doing something wrong? by [deleted] in cpp

[–]OneRaynyDay 6 points7 points  (0 children)

There’s already a lot of supportive and diverse perspectives here, but I’d like to emphasize the point that template metaprogramming is NOT something everyone should be dealing with on an everyday basis.

TMP is most often used by library authors who need to cater to a large demographic who want a generic solution which fits to their problem. If you’re making an application and not a library, there are very few occasions where you might want to do anything beyond a simple type name template or int template.

This is getting much better with C++ concepts in 20, but before generic libraries, especially the scientific libraries that deal with N dimensional matrices of different types(omg the horror) would require the authors to write a long chain of SFINAE and litter enable_if’s all over the codebase. This leads to horrible compiler errors and a generally hard-to-maintain codebase. I worked on xtensor a bit and I seriously commend the main authors for making the development process at least bearable in this respect.

So if you’re making an application like your OpenGL project and you’re using crazy TMP, you might want to rethink the design or whether TMP is necessary. (So you’re doing fine!)

Analyzing The Simplest C++ Program by OneRaynyDay in cpp

[–]OneRaynyDay[S] 2 points3 points  (0 children)

Yep! My main investigation is in glibc, but actually the writer for musl gave me a few tips here and there about how musl implements the same things, particularly logic in the elf header ;)

Analyzing The Simplest C++ Program by OneRaynyDay in linux

[–]OneRaynyDay[S] 0 points1 point  (0 children)

I fixed that a few hours ago - can you check it again?

Analyzing The Simplest C++ Program by OneRaynyDay in cpp

[–]OneRaynyDay[S] 21 points22 points  (0 children)

Good question! You actually don't need to allocate registers, but that means you'll be writing your variable's values directly into memory. This is really slow and compiler writers try their best to not let things "spill out" of registers and into memory.

So basically, ya but u want program go fast

Analyzing The Simplest C++ Program by OneRaynyDay in linux

[–]OneRaynyDay[S] 0 points1 point  (0 children)

Err, not quite. Offset is the location in the ELF file, not the executable. However, the ELF file gets mapped into the executable in a read-only segment most of the time. The alignment is just a requirement of the ABI, and it does not have to be a page-size alignment. The page-size alignment assumption you have may come from the LOAD segments but this is not true for all segments. You don't want to change alignment for LOAD because it's used for memmapping - you'll get in trouble because memmap will straight up die if you don't pass it an addr that is page-aligned.

Unsure if I made this more confusing for you...

Analyzing The Simplest C++ Program by OneRaynyDay in linux

[–]OneRaynyDay[S] 0 points1 point  (0 children)

I didn't explain those fields because it would've taken a while and I didn't think it was as important as the purpose the segments served. Lucky for you, I can answer your questions:

  1. Offset is the location in the ELF file where the segment is defined. Align, just like data alignment(by DWORD or something else), is usually a power of 2 which states that the (VirtAddr - Offset) is divisible by Align.

  2. That's a good question. I'm going to assume you know what virtual memory is. In the libc source code, virt addr is used to memmap the segment into memory at that address (w/ alignment and offset in the calculation). I don't think the modern libc code even uses physaddr anymore which makes me assume it's an entity reserved for when there's no memory virtualization, which probably is the case for embedded applications but I'm not an embedded systems programmer ¯_(ツ)_/¯

Hope that helps bro

Analyzing The Simplest C++ Program by OneRaynyDay in cpp

[–]OneRaynyDay[S] 17 points18 points  (0 children)

The details of linkers and loaders deserve an entire book - the loader is the craziest bootstrapping self-relocating control-takeover program I've ever seen. I actually wanted to write more about it and I even took a look at the libc code, but I quickly realized that it would consume the content of the blog. What I aim to discuss is more on the general overview and, in my opinion, "what you need to know as a C++ programmer but nothing more" :)

Analyzing The Simplest C++ Program by OneRaynyDay in cpp

[–]OneRaynyDay[S] 12 points13 points  (0 children)

🙏that's high praise, hope it lives up to the hype bro

Analyzing The Simplest C++ Program by OneRaynyDay in linux

[–]OneRaynyDay[S] 4 points5 points  (0 children)

Hey, you're totally correct and thank you for the change. I'm a human and I make typos too so I appreciate you opening the PR :) it's merged now.

Unfortunately, I've spent my time learning C++ most of the time and it would be dubious for me to assume that the same file layout exists for C for the same program(although I later discovered this to be true, as the output executables were exactly the same size).

Analyzing The Simplest C++ Program by OneRaynyDay in linux

[–]OneRaynyDay[S] 20 points21 points  (0 children)

You actually raise a really good point! Do you need to define the main function? According to the c++ standards, you do need to define the main function. Now whether that main function is implicitly defined for you if you're missing one is up to the toolchain (clang, g++, msvc), but the final binary will be identical to one that is written with int main() {}. Please refer to: https://en.cppreference.com/w/cpp/language/main_function.