From Newsgroup: comp.lang.c
Tim Rentsch <
tr.17687@z991.linuxsc.com> writes:
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
[...]
For example, this program:
#include <stdio.h>
int main(void) {
const int result = printf("%ld\n", 0.3);
printf("printf returned %d\n", result);
}
on my system prints:
140732048673560
printf returned 16
gcc and clang warn about the format string. tcc doesn't.
The (first) printf call was apparently successful because printf
has no way to know that the argument was of an incorrect type
(types don't really exist at run time).
printf() could know if an argument were of an incorrect type, if
an implementation chose to do so.
Sure. I did write "on my system", where printf has no way to know
that the argument was of an incorrect type.
The "on my system" applies to what the program prints.
The paragraph that says "printf has no way to know" is a general
statement, for any implementation of printf(). If you had meant it
to apply only to your system, you should have said something like
"because that printf had no way to know". Without any qualifying
adjective or other indicator the statement is generic, not
specific.
You're quibbling about something I wrote nearly two months ago.
Certainly printf has no way defined by the language to know whether
its arguments are of the correct types. An implementation could
provide that information via some system-specific method, but I know
of no implementations that do so, and I'd be surprised if any such implementations exist. What I wrote was true on my system and is
very likely true on all real-world systems.
If you have something to say about whether any such implementations
exist, I invite you, but do not expect you, to share it. That might
actually be interesting.
--
Keith Thompson (The_Other_Keith)
Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
--- Synchronet 3.22a-Linux NewsLink 1.2