R
Richard Heathfield
(e-mail address removed) said:
int main(void)
{
int x[256] = {0};
return 0;
}
This code takes advantage of the rules for partially-initialised aggregate
objects to set all x's ints to 0.
Wrong. (And even if you were right, which you are not, the fact that an
implementation accepts faulty code does not imply that it must interpret
that code in the way you expect.)
Your beliefs don't enter into it. Borland C rejects it when invoked in
conforming mode. So does gcc.
Headers aren't about finding the functions. They are for making sure that
the function is being called in the right way.
The normal way to use feof incorrectly is to assume that it is predictive.
It is not.
James said:Johannes Bauer wrote:
(e-mail address removed) schrieb:
int x[256]; // frequencies
Global.
It's completely acceptable to have variables defined at file scope in
C!
What's acceptable is not always a good idea. Global objects have many
disadvantages; they should be avoided except when necessary; they aren't
necessary in this case.
In this case they help simplify the code - the array gets initialized
to 0 at compile-time, instead of needing extra code for an
initialization loop bad for efficiency!
int main(void)
{
int x[256] = {0};
return 0;
}
This code takes advantage of the rules for partially-initialised aggregate
objects to set all x's ints to 0.
But no "conforming implementation" on Windows rejects it!
Wrong. (And even if you were right, which you are not, the fact that an
implementation accepts faulty code does not imply that it must interpret
that code in the way you expect.)
I don't
believe any C compiler anywhere would reject it.
Your beliefs don't enter into it. Borland C rejects it when invoked in
conforming mode. So does gcc.
OK you're right I should remember that. However I don't think it's the
end of the world - the standard library is always linked in so the
right functions will be found in the end by the linker.
Headers aren't about finding the functions. They are for making sure that
the function is being called in the right way.
I don't really understand the problem with feof - it just checks if
the EOF indicator is set in a given FILE * struct. Anyway I'll read
about it.
The normal way to use feof incorrectly is to assume that it is predictive.
It is not.