Planet of the Crabs
🦀 fearless rust


Day 39: Writing malloc wrong, for fun

Posted on by Rust on Julia Evans

My major achievement for today is writing the following five lines of code: let a: ~u8 = ~('A' as u8); stdio::putc(*a); let b: ~u8 = ~('B' as u8); stdio::putc(*a); stdio::putc(*b); and having them do the wrong thing. One would normally expect this to print “AAB”. But for me, right now, until I stop goofing off, it prints “ABB”. Why is that? Well, it’s because my malloc implementation looks like this: