J
Jonathan Bartlett
Greenhorn said:Hi,
We see that C is a bit liberal towards non-standard syntax,
for e.g. when i tried
<printf("string1", "string2 %d", v1);> in Dev-C++, it printed string1
and no error was raised, is this the mistake of standard or the
implementation (Dev-C++).
I was under the impression that the implementations could have been
better by implementing proper rules and adhering to the standard (ANSI
C) at the same time, for e.g., in the above case i was assuming that
the standard would have specified something like "an implementation
MUST provide printf("string where % is special char..", var1,..);". Now
a good implementor could have implemented this along with an error chek
to see the user code strictly adheres to that format and raise an error
if not (my e.g., above).
But, many implementations, even popular ones don't seem to do this.
What do u opine? People who have read the actual Standard can throw
some light on the specification in the standard.
The issue is that the compiler can't necessarily see what you are
passing to printf, and it doesn't really care, either, as printf is a
library function and not an operator. Think of the following things:
1) the format string given to printf could also be a generated value, in
which case the compiler would not even be able to see what it is
2) printf is a library function, so someone could switch it out with
something that has different functionality, but the compiler wouldn't be
aware, and would generate errors even when there were none.
3) The call signature of printf is printf(char *format, ...). This
means that by its call signature, ANY number of parameters (except zero)
are LEGAL, even if the results aren't defined or useful. This is a
limitation of the C language, as this is a limitation of the way C
function prototypes work.
Jon