[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: require() parse error in 5.3.4/5.4.0-work2?
- From: Sean Conner <sean@...>
- Date: Wed, 27 Jun 2018 13:02:03 -0400
It was thus said that the Great Kenneth Lorber once stated:
> > On Jun 23, 2018, at 8:57 AM, Andrew Gierth <email@example.com> wrote:
> > Pretty much every function accepts and silently ignores extra arguments,
> > unless the function itself bothers to check for them and throw an
> > explicit error.
> Thanks, and after a little source diving you are correct, but that's not
> quite the reply I was looking for.
> Is there some reason this is a language feature? Some use-case I don't
> see? (If so, why is there the occasional check for extra arguments?)
It's not just Lua. Here's an example in C:
----[ x.c ]------
extern int foo();
int x = foo(1,2,3,4,5);
----[ y.c ]-----
extern foo(int,int); // to shut up clang
int foo(int a,int b)
return a + b;
[spc]dynamic-147:/tmp>gcc -ansi -pedantic -Wall -Wextra x.c y.c
[spc]dynamic-147:/tmp>clang -ansi -pedantic -Wall -Wextra -Weverything x.c y.c
No warnings. No errors. I'm passing way more parameters to foo() than it
is expecting. And it works. Granted, I'm using an outdated style of
function prototype which in C means "this function takes an unspecified
number of arguments and returns an integer" (at least in x.c; y.c has the
proper prototype, but that's to shut up clang about a missing function
prototype that GCC doesn't report).
> Is it documented somewhere I missed?
> Is there any reason not to add checks for extra arguments? If it's
> performance, it could be available as a compile time option.
It's performance, and it doesn't hurt. I'm also not sure how easy it
would be to catch at compile time.