Re:Humans should think of sizeof() as a function, says Linus...
by hueving on Saturday May 30, 2015 @11:48AM
(#9630542)
He is talking about C. Continuations are irrelevant.
Re:Humans should think of sizeof() as a function, says Linus...
by kazinator on Saturday May 30, 2015 @02:46PM
(#9631274)
That point is clearly made in the comment you're replying to, with the additional point that if we are talking about C, then sizeof is an operator, not a function. It doesn't require parentheses, except when its operand is a type expression. No well-considered coding convention requires superfluous parentheses with sizeof, and there are good reasons to ban them.
We should prefer code like:
type *ptr = malloc(sizeof *ptr); /* no parens */
to type *ptr = malloc(sizeof (type));
In general it's often better to base sizeof on an ordinary expression rather than a type expression.If we don't use superfluous parentheses on sizeof, we can then look for sizeof followed by an open parenthesis to look for code where sizeof is applied to a type expression.
sizeof (type)
means "produce me a size_t value based on some arbitary type, without checking that it's related to anything in the surrounding code". It can be as dangerous as a (type) cast.
Re:Humans should think of sizeof() as a function, says Linus...
by newuser88273 on Sunday May 31, 2015 @10:39AM
(#9634285)
Scheme has come up with the idea of pretending that an undelimited contination is a function, which is somewhat true-ish... in the degenerate sense of a function with empty domain.
This is fine for Scheme, which is an expression language, so every method of invoking a continuation would, syntactically, be an expression anyway.
In C, which has statements, making return look like an expression is somewhat pointless. It doesn't matter whether C "has" continuations (and it arguably has) or not.
Re:Humans should think of sizeof() as a function, says Linus...
by anonbanker on Saturday May 30, 2015 @12:02PM
(#9630577)
Why shouldn't return be considered a function?
We can justify writing return (expr); using the same arguments that justify the sizeof (expr) convention.
The thing is that in C, return isn't a function; there are no continuations.
Similarly, sizeof is an operator, which doesn't reduce its argument expression to a value.
If we are going to make coding conventions based on pretending that C is a different language in which sizeof is a function, then pretending return is a function is also fair game.