4 ms·
Somehow over the years learning C on my own, perhaps because it seemed more consistent to me, I got used to writing if(foo) { omitting the space after con
by comex 13y ago
Somehow over the years learning C on my own, perhaps because it seemed more consistent to me, I got used to writing
if(foo) {
omitting the space after control statements' names, which is almost never done - except in very early C code. (It's not just this: V7 Unix often omits the space as well.). I should probably settle on a less idiosyncratic personal style, but I can't help but take a little heart from seeing "my" style in such a famous codebase. :)
- PySlice 13y agoNever using a space before the paren is more consistent. I don't know why people put a space there...
- brianberns 13y agoif(foo) I avoid doing this because it looks like a function call.
- kybernetikos 13y agoIn an appropriately powerful language, it could be a function call.
- a1369209993 13y agoafter #define if(X) LET(_it,X) if (_it) it would be a macro call
- yoklov 13y agoI'm fairly certain that shadowing a keyword with a macro is forbidden by the standard (or invokes UB?) but this will still work for most compilers, provided LET is defined reasonably. Hm, something like #define LET(name, X) \ for (int let_once_=1, name=(X); \ let_once_; \ let_once_=0) may be reasonable, though tokenpasting in __LINE__ for good measure might be necessary for nesting.
- 30thElement 13y agoShadowing keywords is perfectly valid, although I believe you can't shadow keywords in standard headers so that compiler writers don't need to worry about it. It gives rise to some "useful" C/C++ features that should never be used, like if you want to access private members in foo.cpp, do #define private public #include "foo.cpp" #undef private
- TazeTSchnitzel 13y agoI can imagine some insidious menace adding this to the top of a file: #define public protected
- yoklov 13y agoI once someone jokingly do (the second only always works in C, not C++) #define else #define struct union Evil!
- TheBoff 13y agoThis is all very well if you have a friendly, high level scripting language like Ruby, but I'm definitely glad I don't have to write a C compiler where functions can take arbitrary blocks of code.
- deleted 13y ago[deleted]
- mseepgood 13y agoIt was also defined in the Plan 9 code style: http://plan9.bell-labs.com/magic/man2html/6/style http://plan9.bell-labs.com/magic/man2html/6/style "no white space after the keywords if, for, while, etc."