4 ms·
This is incorrect. In a function definition, an empty list means it takes no parameters. 6.7.5.3 Function declarators > 14. An empty list in a function declara
by tedunangst 1y ago
This is incorrect. In a function definition, an empty list means it takes no parameters. 6.7.5.3 Function declarators
> 14. An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters.
- s3graham 1y agoAs you surely know if you're quoting the standard, it depends on which standard!
- gpderetta 1y agoI believe that since C23 foo() is now a nullary function. As this is the last approved standard and it supersedes all previous standards, it is technically correct to say that de-jure this is what the (unqualified) C standard mandates. Of course de-facto things are more nunanced.
- el_pollo_diablo 1y agoC23 does not change anything in this situation, because we are talking about the definition of main(), not a forward declaration. More details here: https://news.ycombinator.com/item?id=38729278#38732366 https://news.ycombinator.com/item?id=38729278#38732366
- fuhsnn 1y agoIn what situation fn() doesn't mean fn(void) under C23?
- el_pollo_diablo 1y agoNone, but that is not my point. Before C23, fn() already meant the same thing as fn(void) in function definitions, which the situation under discussion here. C23 changed what fn() means outside a function definition.
- fuhsnn 1y agoOh, yeah, the codegen for the fn() itself would likely be the same, but the prototype of that definition is still a K&R function. https://godbolt.org/z/Psvae55Pr https://godbolt.org/z/Psvae55Pr
- tedunangst 1y agoQuote a different standard.
- zombot 1y ago"has no parameters" is not the same as "cannot take arguments". Defining `int main()` does not stop the runtime from passing the usual 3 arguments (typically named argc, argv, envp), it only means that no parameters are bound to those arguments. Technically it's no problem to have a C function ignore its arguments by not binding parameters. Way too many programmers seem to not understand the difference between parameter and argument. https://stackoverflow.com/questions/156767/whats-the-difference-between-an-argument-and-a-parameter?page=1&tab=scoredesc#tab-top https://stackoverflow.com/questions/156767/whats-the-differe...
- MangoToupe 1y agoSurely part of the problem is having a distinct term and handling for parameters passed to functions. What is the point? It seems confusing with no upside.
- zombot 1y agoDo you find the difference between abstract and concrete confusing? Or the difference between container and contents? Is that a pointless distinction with no upside?
- MangoToupe 1y agoI do agree these are useful concepts to distinguish, but I don't get the connection to the topic at-hand. To me, there is just the function signature. I don't see a benefit to referring to passed values as distinct from received values. To my ear "argument" and "parameter" are perfect synonyms.
- antonvs 1y ago> referring to passed values as distinct from received values. That’s not the distinction being made by those terms. “Parameter” refers to a named variable in a function definition. “Argument” refers to an actual value that’s passed to a function when it’s called. It’s exactly the same as the distinction between variables and values (which you probably see the use for), just applied to the special cases of function signatures and function calls. (As an aside, in the lambda calculus this relationship becomes a perfect equivalence: all variables are parameters and all values are arguments.)