On Fri, Mar 22, 2019 at 01:28:39PM +0100, David Brown wrote:
> If you compile a "hello, world!" C program, then the C standards do not
> define how those words get on your screen.  As far as /C/ is concerned,
> the workings of "printf" are undefined behaviour - because the C
> standard does not define them.

No, printf behavior is not undefined behavior.  It is defined in terms of
behavior on the streams (e.g. C99 7.19.2) and the exact streams behavior has
some well defined and some implementation defined parts.

Undefined behavior is not something not specified in the C standard, it is
when the C standard says that in such and such case the behavior is
undefined.

The glossary (C99) says:

implementation-defined behavior
unspecified behavior where each implementation documents how the choice is made

EXAMPLE An example of implementation-defined behavior is the propagation of the 
high-order bit
when a signed integer is shifted right.

undefined behavior
behavior, upon use of a nonportable or erroneous program construct or of 
erroneous data,
for which this International Standard imposes no requirements

NOTE Possible undefined behavior ranges from ignoring the situation completely 
with unpredictable
results, to behaving during translation or program execution in a documented 
manner characteristic of the
environment (with or without the issuance of a diagnostic message), to 
terminating a translation or
execution (with the issuance of a diagnostic message).
EXAMPLE An example of undefined behavior is the behavior on integer overflow.

        Jakub

Reply via email to