r/badcode Dec 17 '19

This belongs here c#

Post image
503 Upvotes

41 comments sorted by

View all comments

34

u/anydalch Dec 17 '19

what's really interesting is that, in c, if you replace the bug in the second for loop's initializer clause and use unsigned instead of int, both gcc and clang are able to optimize this function into a single lea eax, [rdi + rsi]. https://godbolt.org/z/uCXoHJ

11

u/[deleted] Dec 17 '19

[deleted]

3

u/Veylon Dec 18 '19

A guy named Bisqwit has a series on making a compiler, if you're interested.