Re: Why oh why does this NOT give a compile error?
- From: James Kuyper <jameskuyper@xxxxxxxxxxx>
- Date: Mon, 05 Nov 2007 12:38:57 GMT
Paul Melis wrote:
Can someone explain to me why the following code compiles without
errors on gcc 4.0.2?
void f()
{
}
void t()
{
f(1,2,3);
f("1");
}
I would expect at least some warning, but not even that. Is this a
feature of the newest C dialect or something, that you can provide
arbitrary arguments to a function having no arguments?
No, it's a feature of the C standard that this code has undefined behavior, but is neither a syntax error nor a constraint violation, and therefore does not require a diagnostic message. A good compiler might provide one. The more fundamental problem is that you should be using function prototypes, in which case the corresponding code would require a diagnostic message.
What compiler options are you using? With the right compiler options, gcc can be a good compiler, though what it produces is a warning about the more fundamental problem, rather than the one you're actually asking about:
cc -std=c99 -pedantic -Wall -Wpointer-arith -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -c -o ft.o ft.c
ft.c:2: warning: function declaration isn’t a prototype
ft.c:6: warning: function declaration isn’t a prototype
.
- Follow-Ups:
- Re: Why oh why does this NOT give a compile error?
- From: ups_genius
- Re: Why oh why does this NOT give a compile error?
- References:
- Why oh why does this NOT give a compile error?
- From: Paul Melis
- Why oh why does this NOT give a compile error?
- Prev by Date: Re: C Questions
- Next by Date: Re: Why oh why does this NOT give a compile error?
- Previous by thread: Re: Why oh why does this NOT give a compile error?
- Next by thread: Re: Why oh why does this NOT give a compile error?
- Index(es):
Relevant Pages
|
|