[cfe-dev] can foo() be called with arguments?

Eli Friedman eli.friedman at gmail.com
Sun Feb 17 11:17:08 PST 2008


On Feb 17, 2008 10:30 AM, Török Edwin <edwin at clamav.net> wrote:
> From my reading of the C99 standard (N1256.pdf) calling foo with
> parameters when it is declared as foo() is allowed only if the
> declaration doesn't involve a definition too.
> If it involves a definition, then you can't call it with parameters,
> and foo() is equivalent to foo(void). Is this correct?

See http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_317.htm.
Essentially, executing the call is technically undefined behavior, but
it's a perfectly legal construct.  I've filed
http://llvm.org/bugs/show_bug.cgi?id=2042 on the issue.

It looks like your module does actually execute such an undefined
call, so the program technically has undefined behavior.  That said,
I've never heard of a C compiler producing code that actually did
anything weird... generally, C calling conventions allow for an
arbitrary number of arguments even if the callee doesn't expect them
for compatibility reasons.

-Eli




More information about the cfe-dev mailing list