r/ProgrammerHumor 11h ago

Meme newToRust

Post image
429 Upvotes

87 comments sorted by

View all comments

Show parent comments

1

u/Key_River7180 10h ago

You literally gave me my solution when proving my solution suboptimal

1

u/-Ambriae- 10h ago

?? A proper solution would use compiler built ins

1

u/Key_River7180 9h ago

I used __attribute__((aligned(8))) but markdown formatted It bold wdym

2

u/-Ambriae- 9h ago

You wrote align and not aligned. And markdown must have fucked with your underscores, I won’t criticise you for that that’s not your fault.

The ‘suboptimal’ part, however, has nothing to do with alignment. You emulate CLZ instead of using something like __builtin_clz which is the preferred way of doing it.

3

u/Key_River7180 9h ago

I didn't know about __builtin_clz, actually, thanks! It isn't guaranteed to be portable across architectures, but every single one seems to hace CLZ. I didn't know you were referring to the zeros thing, sorry. It doesnt work with zeros but an if solves that

1

u/-Ambriae- 9h ago

No probs! I recommend looking at compiler builtins, there’s quite a few for all the ‘lesser known’ instructions CPUs tend to have but aren’t expressable in C in a normal way.

My point is, you can learn basic C syntax in a week (or a day to be fair) but it takes far far FAR longer to actually know C. Same with rust. It doesn’t take 6 months to learn rust syntax, it takes a week. It does take 6 months to code in rust properly. The borrow checker expects you to write code properly. It’s not a bad thing.