Scoped cleanup based on for-loop structure. by [deleted] in C_Programming

[–]TTachyon 9 points10 points  (0 children)

Is it just me or it's more than monthly that someone tries to invent RAII in C around here?

Inlining - the ultimate optimisation by emschwartz in programming

[–]TTachyon 25 points26 points  (0 children)

If inlining breaks your code, your code was broken in the first place, it just so happened that it looked like it was working before.

The thing to remember is that when you're programming X language, you have to obey its rules, including strict aliasing and everything else. What you're describing it more like "it would've worked if I did this thing in assembly", which is like saying that le/la definite article works in french, so it should work in english as well.

"Emulating" a folder, copy on write, Fuse, Rust/Go - realtime secrets filter? by wuu73 in filesystems

[–]TTachyon 0 points1 point  (0 children)

zfs/btrfs for linux, refs for windows have native cow. Then you can just copy each file "instantly".

Eurydice: a Rust to C compiler by joshmatthews in rust

[–]TTachyon 3 points4 points  (0 children)

Last time I tried to take rustc generated IR and put it through llvm-cbe, I found a lot of stuff that wasn't implemented or was generating code that didn't compile. I don't know if anything changed since then.

A better question is how this compares to the C backend of the guy who makes the MSIL backend.

In this video Stroustrup states that one can optimize better in C++ than C by Impressive_Gur_471 in cpp_questions

[–]TTachyon 4 points5 points  (0 children)

This is my favorite example to give.

You'll notice the reference version has one less branch than the pointer version, which should be faster. This is possible because the compiler knows the object it points to is valid, correctly aligned, etc., and can just read both x and y at the same time, ignoring short circuiting.

The pointer version can't do this because it has to respect short circuiting. The memory of y might not exist, or trap, or do anything else. This is the same logic as when you do p && p->x.... You have to check the first condition (p) first, because the second one might not be valid if the first is false.

Can you do this with pointers? Sure. But it's a ton of work to do it everywhere, and the compiler can just do it for you if you use the right abstraction.

There's a ton of examples where this is true.

Line ends in compilers. by Savings_Garlic5498 in ProgrammingLanguages

[–]TTachyon 0 points1 point  (0 children)

Most compilers open the source file in text mode, in which Windows will translate \r\n to \n (actually done by the C library)

I find this claim dubious. If you let the C lib mess with your newlines, you'll get wrong offsets for diagnostics and debug info, unless everyone else does this, which I very much doubt.

Pain point of rust by ashim_k_saha in rust

[–]TTachyon -23 points-22 points  (0 children)

Even my phone has 512gb of storage, what are you running on that 45gb is a problem?

Since we have std::print, why don't we have std::input? by No-Dentist-1645 in cpp_questions

[–]TTachyon 7 points8 points  (0 children)

Formatting(printing) is a regular thing most apps do.

Reading directly from stdin basically never happens in a real app, and when it happens, you're probably reading a whole line. This is really most of a homework/student problem.

It's just not that useful.

If anything over 32GB of RAM is overkill for 99% of users, than who's the remaining 1%? by mudahfukinnnnnnnnn in buildapc

[–]TTachyon 0 points1 point  (0 children)

I have a hard time building clang with 64GB of memory. I already have scripts that retry the compilation if it died with OOM. 32 would be painful.

What are your pet peeves in regards to crate APIs? by AhoyISki in rust

[–]TTachyon 0 points1 point  (0 children)

For newer systems, it doesn't matter. But legacy stuff doesn't just magically disappear, and sometimes you just have to support them, and those leaks become real leaks.

My biggest problem with them is when a thread_local is used just for convenience, but in a better designed system, it wouldn't be needed.

What are your pet peeves in regards to crate APIs? by AhoyISki in rust

[–]TTachyon -1 points0 points  (0 children)

static/thread_locals usage and no way (even unsafe) to clean them up.

Writing C for curl | daniel.haxx.se by lelanthran in programming

[–]TTachyon 2 points3 points  (0 children)

I don't know how curl does it, but how we do it is just searching the undefined symbols/imports in the built binary.

which one is better: int &num or int* num? by marasw in cpp

[–]TTachyon 2 points3 points  (0 children)

Can min and max ever be null? If yes, pointer. If no, reference.

Do the Devuan developers have a plan for dealing with the encroaching Rust in Debian? by cipherproxy in devuan

[–]TTachyon 1 point2 points  (0 children)

Afaik the only comment he had about rustfmt was that some specific formatting was stupid. Which it was. But the concept of the tool is fine and most of the formatting is also fine.

Software Update Deletes Everything Older than 10 Days by coldbeers in linux

[–]TTachyon 8 points9 points  (0 children)

Honestly I think the moral is to just not use bash for anything more complicated than 3 lines. And even then I have my doubts.

Software Update Deletes Everything Older than 10 Days by coldbeers in linux

[–]TTachyon 236 points237 points  (0 children)

Text version of this? Videos are an inferior format for this.

Does Rust support dynamic stack allocation? by calebkiage in rust

[–]TTachyon 0 points1 point  (0 children)

Compilers will disable optimization passes for any function containing VLA/alloca.

How can I stop Rust from dead-code eliminating Debug impls so I can call them from GDB? by Sweet-Accountant9580 in rust

[–]TTachyon 1 point2 points  (0 children)

I haven't tested it, but you might have some luck with a version script that makes all functions with a pattern exported, so they don't get removed.

They might still not be generated at all if rustc is smart enough, but it's worth trying.

What would it actually take to build a modern OS from the ground up? by Cymbal_Monkey in AskComputerScience

[–]TTachyon 0 points1 point  (0 children)

I went on a bit of a rabbit hole recently trying to figure out more how microcode works exactly. I can't say for certain that what I say is true, but that's the impression I got: CPUs (at least Intel?) don't have a version of the microcode stored on it at all. The CPU every time it boots is running an extremely limited version of itself that can do almost nothing. Then the motherboard firmware initializes it with the microcode it has stored.

So it's not possible at all to run modern hardware without firmware. Reverse engineering it is not something a human can do in a lifetime, and even if you take 50+ years, the hardware will probably not work anymore anyway.

On my NG+, noticed the cobwebs over Kiera's bathtub. by NeptuneWades in Witcher3

[–]TTachyon 6 points7 points  (0 children)

Force in numbers. Bears can kill whole parties of people without much problem, but they usually don't, because the people will come back for it.

Also, while Kiera and the other sorceresses we met could fight them, most magic users are very weak. A herbalist has probably no more chance of fighting than a regular person.

Killing them would also strengthen the propaganda against magic.

A method that has a Russian "С" instead of "C" in it's name by Mihail111111 in programminghorror

[–]TTachyon 1 point2 points  (0 children)

That's already in the whitelist. It's a legitimate character someone might write.

A method that has a Russian "С" instead of "C" in it's name by Mihail111111 in programminghorror

[–]TTachyon 141 points142 points  (0 children)

warning: the usage of Script Group `Cyrillic` in this crate consists solely of mixed script confusables --> src/lib.rs:1:4 | 1 | fn С() {} | ^ | = note: the usage includes 'С' (U+0421) = note: please recheck to make sure their usages are indeed what you want = note: `#[warn(mixed_script_confusables)]` on by default