Liste des Groupes | Revenir à cl c |
On 13/06/2024 22:47, Keith Thompson wrote:Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:And this is how things break.On 13/06/2024 01:33, Keith Thompson wrote:Not at all. Compilers commonly diagnose mismatches when the formatprintf 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.
>
string is a string literal, as it most commonly is. The format
specifier for size_t is "%zu", since C99.
We can and do.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.
>
Now, running a third party editor under your control so that user can
edit an text and return control and the edited text back to you when
he exits the editor. Yes, I understand that this is a difficult thing
to do, the software engineeering isn't consistent, and theway you have
to do it may change from one version of C to another.
But printing out a variable which holds the length of a string? And
something so basic breaks from one version of C to the next? We should
ahave no tolerance for that at all.
Les messages affichés proviennent d'usenet.