by unwind · 2y ago · 0 comments
So
return (1);
instead of just return 1;
I remember using the former style as I tried (in frustration) to learn C back on the Amiga (so roughly at the same time, late 80s/early 90s) using articles in magazines.Does anyone know where it comes from?
Some time later (late 90s) at university I learned C again but with actual (good!) teachers, and also got exposed to way more code and talk about code thanks to Internet and comp.lang.c etc, and around that time (I think?) I stopped using them.
Nowadays they always make me think the author is anxious that the function will return before the entire expression is evaluated, which makes me smile. :)
Matt Dillon's DICE would have been popular on the Amiga then, and it looks like it also favored parens. The latest tarball of DICE² is pretty fun for a spelunking session, if you're feeling nostalgic. It makes for an interesting mix as it pulls in a few contemporaneous non-Dillon tools with varying styles.
Back then C was rare on home computers. Programmers were more used to BASIC where typically GOSUB / RETURN couldn’t return a value at all.
Eventually I stopped because it saves 1 byte and means pressing fewer keys.
return 1;
is visually closer to return;
than return (1);
is.So this could be a way of signaling "hey, I'm returning a value here, not just leaving the function".
But I'm just speculating...
`return( 1 );`
not `return (1);`
...because the bracket belongs to the return, not the expression. It's by analogy with 'if' and 'while', a mental "look out, here comes an expression" warming.