karthikbalaguru said:
But, why do i get a warning in gcc but
it is showing an error in VC++ 6.0 ?
I wonder how these compilers have
different rules at different scenarios.
They're written by different people using different methods for
different purposes.
Aren't the C standard made to be followed
by the compilers ? Strange !!
Yes, but you need to understand what it is that the C standard requires.
You seem to have some serious misconceptions about that.
The C standard requires any conforming implementation of C must
translate and correctly execute one program. It is a program chosen by
the implementor. It has to meet certain requirements set by the
standard, but those requirements allow it to be functionally equivalent
to int main(void) {return 0;}
The standard does NOT require that any other program must be translated
and correctly executed.
The C standard requires that conforming hosted implement of C must
accept any strictly conforming program (a very restricted set of
programs, that excludes virtually all useful programs). However, unlike
the "one program" described above, the standard doesn't actually require
such programs to be translated and correctly executed, only that they
must be accepted.
The standard does NOT require that any other programs be accepted.
The C standard requires that a C compiler reject a program when it
contains a #error directive that survives conditional compilation, in
which case it is required to issue a diagnostic containing the text
associated with that directive.
The standard does NOT require that any other program be rejected, no
matter how serious it's defects are, even if it contains a defect so
severe that a diagnostic is required.
The C standard requires that an implementation must issue at least one
diagnostic when processing any program that contains a syntax error, a
constraint violation, or any other situation in which the standard
specifies that a diagnostic is required. The C standard does NOT specify
that more than one diagnostic be issued, nor that the diagnostic give an
adequate explanation of the problem that made it mandatory; in fact, the
diagnostic doesn't have to explain anything: it could be the phrase
"Toodle loo!".
The standard does NOT prohibit an implementation from issuing any
diagnostics it wants, for any reason it wants. In particular, a
conforming implementation is allowed to generate misleading or even
downright false messages about your code, or your weight, or about your
ancestry.
When code has behavior that is undefined according to the C standard,
that means that the C standard imposes no constraints on it, of any
kind. A conforming implementation isn't required to accept it, nor is it
required to reject it. It isn't required to generate a diagnostic, nor
is it prohibited from generating a diagnostic. The standard doesn't
require that the code behave the way you expect it to; the standard also
doesn't prohibit it from working exactly the way you expect it to.
If you look that list over, you'll see that compilers have a lot of
freedom to decide how they will deal with defective code, while still
conforming to the C standard. Therefore, would you please stop being
surprised when different compilers conforming to the same standard
handle defective code in different ways? It's getting irritating.