4 ms·
I guess the use case is to quickly try out some C/C++ code snippet. Typically I can think of checking binary arithmetic operations behavior. Say you have some
by Galanwe 3y ago
I guess the use case is to quickly try out some C/C++ code snippet. Typically I can think of checking binary arithmetic operations behavior.
Say you have some buffer that you need to align on 4K blocks, you could quickly try out your "& ~0x1000" in the REPL. It may not be a convincing example, but you get the gist, sometimes you just want to quickly see the result of some one liners.
- PennRobotics 3y agoI did what you described just yesterday. I couldn't remember offhand if the compiler I was using would automatically convert a uint8_t to an int (because I didn't want to have to add two levels of parentheses by explicitly casting the high byte and then shifting) and very quickly threw together a // test if we need a<<8|b // or (a<<8)|b // or ((int)a<<8)|b // or (((int)a)<<8)|b #include <cstdio> #include <cstdint> int main() { uint8_t a = 2; uint8_t b = 38; printf("%d\n", a<<8|b); } More than half of the time is the uninteresting parts: writing the includes, creating a temp file, exiting to compile, forgetting a parenthesis, reediting and resaving, compiling again, running, deleting... In a REPL---particularly one with stdio/stdlib included by default---this would take 30 seconds but instead takes 3 or 4 minutes. It's not much, but tight feedback loops really, really keep you in a great mental state.