6 ms·
In high school (1996?) I was teaching myself C to write a small game and I had forgotten to add "break" at the end of each case within a switch statement. I was
by natnatenathan 4y ago
In high school (1996?) I was teaching myself C to write a small game and I had forgotten to add "break" at the end of each case within a switch statement. I was developing by myself (not quite in my mother's basement, but close enough) before I had access to the internet or stack overflow. It took me months to figure out the error. When I finally figured it out I was so embarrassed.
- mananaysiempre 4y agoThis seems to be a common pedagogical problem in expositions of C — so few of them point out that no, damn it, `switch` is not a multi-arm `if`, it’s a computed `goto` with lipstick on it (as opposed to an actual computed GO TO like the one in Fortran).
- nerpderp82 4y agoMany compilers allow for emitting the original source interleaved with the assembly output. It is a great way to understand the code, as well as stepping through in a debugger. With small scale computation (single process, single node), we have control over the entire universe. We just have to realize it and then figure out how to introspect it. @natnatenathan I am glad you stuck with it, but the cognitive flaw that is very hard to get over is broken partial information. We have to rollback (forget our knowledge) and then learn it again fresh which can be incredibly hard, we skip over things we "think" we already know.
- WalterBright 4y ago> Many compilers allow for emitting the original source interleaved with the assembly output. My object file disassembler will do that: https://www.digitalmars.com/ctg/obj2asm.html https://www.digitalmars.com/ctg/obj2asm.html if the source code was compiled with debug info turned on. This feature has been around at least since the 80s.
- mananaysiempre 4y agoSo will objdump (or llvm-objdump) with -dS, for that matter (hint: -Mintel or, on older llvm-objdump versions, --x86-asm-syntax=intel), except the line numbers in both GCC and Clang’s debug info suck in optimized builds. (Not the fault of the debug info, arguably, it’s just that the optimizer rearranges the code to the extent that the notion of line numbers makes little sense.)
- WalterBright 4y ago> the optimizer rearranges the code to the extent that the notion of line numbers makes little sense I remember PhD papers addressing that in the 1980s. Nobody has yet figured out how to revert optimizer hamburger back into source meat.