I changed add to be a bit more useful, otherwise the compiler can completely optimize everything away. When compiling the minimal example in release mode and then disassembling it, we get some very nice assembly:
I really like this as a teaching example, but it's still quite advanced. In order to understand this code the student will need to know about C calling conventions, the stack, and more. So I don't think we can start here, but this would be nice to get to after covering more of the basics.
I changed add to be a bit more useful, otherwise the compiler can completely optimize everything away. When compiling the minimal example in release mode and then disassembling it, we get some very nice assembly:
I really like this as a teaching example, but it's still quite advanced. In order to understand this code the student will need to know about C calling conventions, the stack, and more. So I don't think we can start here, but this would be nice to get to after covering more of the basics.