Liste des Groupes | Revenir à cl c |
On 13/06/2024 01:33, Keith Thompson wrote:printf is a variadic function, so the types of the arguments afterAnd isn't that a nightmare?
the format string are not specified in its declaration. The printf
function has to *assume* that arguments have the types specified
by the format string. This:
printf("%d\n", foo);
(probably) has undefined behavior if foo is of type size_t.
>
There is no implicit conversion to the expected type. Note that>
the format string doesn't have to be a string literal, so it's
not always even possible for the compiler to check the types.
Variadic functions give you a lot of flexibility at the cost of
making some type errors difficult to detect.
(I wrote "probably" because size_t *might* be a typedef for unsigned
int, and there are special rules about arguments of corresponding
signed and unsigned types.)
We just can't have size_t variables swilling around in prgrams for
these reasons.
Les messages affichés proviennent d'usenet.