3 ms·
You could do it by separating the body with a semicolon: if something_is_true(); log("warning!") I haven't really considered the preprocessor as I prefer
by SupremumLimit 12y ago
You could do it by separating the body with a semicolon:
if something_is_true(); log("warning!")
I haven't really considered the preprocessor as I prefer to avoid it as much as possible.
- sanxiyn 12y agoThis doesn't work. "if a; if b; c; d" is then an ambiguous parse to both "if (a) { if (b) { c; d; } }" and "if (a) { if (b) { c; } d; }". If you decide to parse one way, how do you write the other one in a single line?
- SupremumLimit 12y agoI'd make this parse as "if (a) { if (b) { c; d; } }" and leave it at that. One of the reasons for significant indentation is to discourage this kind of code layout because it's hard to read.
- sanxiyn 12y agoOkay, concretely, I'd like to see a translation of this real-world C++ code (taken from V8): #define RETURN_OBJECT_UNLESS_EXCEPTION(ISOLATE, RETURN_VALUE, RETURN_EMPTY) \ if (!__allocation__.IsRetry()) { \ __object__ = __allocation__.ToObjectChecked(); \ if (__object__ == (ISOLATE)->heap()->exception()) { RETURN_EMPTY; } \ RETURN_VALUE; \ }
- SupremumLimit 12y agoThis seems to be missing backslashes. I haven't considered how to deal with preprocessor macros, but the if statement converts very simply: if !__allocation__.IsRetry() __object__ = __allocation__.ToObjectChecked() if __object__ == (ISOLATE)->heap()->exception(); RETURN_EMPTY RETURN_VALUE This isn't ambiguous like the example you suggested before.
- sanxiyn 12y agoThat doesn't work, because if statement is inside preprocessor macro and must be in a single line.
- SupremumLimit 12y agoI see what you mean. Yes, the if in a macro is a problem. I haven't addressed macros, that's a whole different can of worms.