Re: Why oh why does this NOT give a compile error?
- From: ups_genius@xxxxxxx
- Date: Mon, 05 Nov 2007 06:35:07 -0800
On 5 Nov., 13:38, James Kuyper <jameskuy...@xxxxxxxxxxx> wrote:
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- Zitierten Text ausblenden -
- Zitierten Text anzeigen -
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.
Exactly!
Things that are "correct" in C might still not always be the best
solution.
Think about the following:
(array[i] == i[array]) will return (!0)
array[i] is the same as i[array], and it is perfectly correct in C.
But you still would not want to use it.
Why?
array[i] == *(array+i) == *(i+array) == i[array]
Christian
.
- References:
- Why oh why does this NOT give a compile error?
- From: Paul Melis
- Re: Why oh why does this NOT give a compile error?
- From: James Kuyper
- Why oh why does this NOT give a compile error?
- Prev by Date: Re: Bug/Gross InEfficiency in HeathField's fgetline program
- Next by Date: Re: mnemonic
- 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
|