W
Wojtek Lerch
Sidney said:>
>
> Not at all. It's just that I would have appreciated a disclaimer stating
> something like this:
>
> "The execution environment may impose semantics / side effects in
> addition to (but not contradicting) the semantics and side effects as
> defined in this standard, for the following I/O related functions: ..."
>
> Is that so much to ask?
The standard has a tendency to avoid saying things that are obvious.
Implementations may do whatever they want, as long as they meet all the
requirements defined in the standard. In particular, implementations
are free to give promises to their users that go beyond what the C
standard requires. If a compiler is sold in a box that claims to
contain 97% recycled paper but in reality only contains 95%, isn't it
quite obvious that that little lie doesn't affect the compiler's
conformance to the C standard?
....
>
> That is answerable. A call has a side effect if there is a detectable
> effect in the outside world of the call having been made, i.e., there is
> a detectable difference between the effects on the execution environment
> of a run of the program and a run of a derived program that is equal to
> the original, except that this one call did not take place.
That's a circular definition. If an implementation optimizes the call
away, there's no detectable difference, and therefore it was OK to
optimize it away.
On the other hand, if another implementation doesn't optimize it away,
the derived program takes up less space in the execution environment --
isn't that a detectable difference?
>
> Which definition of "side effect" are you using here?
Any definition you can think of. Since the call has been optimized
away, it can't have any effects whatsoever.
>
> He couldn't, and doesn't have to. What is important is that he knows
> from the standard that the call *may* have a side effect.
You seem to have it backwards. The implementor *implements* the call.
He writes the code. The standard tells him what the call must do and
what it mustn't do, and then he decides how to write code that does all
the required things but doesn't do any of the forbidden things. If the
standard says that the call may but may not have side effects (by
whatever definition of "side effects"), the implementor is free to
choose whether to write code that produces such side effects or code
that can be optimized away.
....
> The standard tries quite hard to provide a situation where compliancy of
> an implementation can be judged based on the text of the standard alone,
> i.e., it is (or attempts to be) self-contained.
Yes. That's the purpose of having a standard.
> I would argue that this fails (where else) with its handling of the
> concept of side effects. These cannot be properly defined without
> references to "outside the C box", I think; so then you're left with a
> number of options. My preference would be to be "intentionally vague"
> rather than an (IMHO) misguided attempt to provide a definition.
The authors of the standard described a concept they wanted to use in
the text, and decided to name it "side effects". They excluded things
like file attributes from their definition because they didn't want
implementation conformance to the C standard to depend on how
implementations define and handle file attributes.
If you ask whether the C standard requires fopen() to change file
attributes, the answer is a clear no. You might not like that answer;
but it doesn't make much sense to say that instead the standard should
say, "no, except when the implementation says yes and maybe perhaps in
some other circumstances that we can't think of right now". Just like
it wouldn't make sense for the C standard to say that if the box
specifies how much recycled paper it contains, or if the country it's
sold in requires all boxes to contain a certain minimum of recycled
paper, then it must indeed contain at least that much.
> Of course I've said the same thing in different words a dozen times now.
> Please note that I'm perfectly happy to accept that some things are
> defined outside the C scope (e.g. in POSIX), but the C standard should
> write a couple of lines about that and its relation to such things,
> that's all I ask.
Isn't it good enough that those other things explain their relation to
C?
....
>
> No. You are hitting on precisely the reason why it is so hard to define
> "side effects" in the way that one would like. But you and I have an
> intuitive idea. I'd prefer a sound definition, but on the other hand I
> prefer a somewhat vague notion over a faulty definition.
I don't know about you, but my intuitive idea is that it depends on the
context. For instance, when I'm talking about medicine (or even about
POSIX), I don't necessarily try to apply the C standard's definition
when someone says "side effects". But when I'm reading the C standard,
my intuition tells me that I should interpret it exactly the way the
definition says. If the result didn't seem to make sense, then I could
suspect that something were wrong either with the definition or with how
the term is used. But my intuituion tells me that everything is OK.
....
>
>
> I presume your question is designed to convey the idea that the C
> standard doesn't have the notion of a platform, as currently written?
Correct. There is not a single occurence of the word "platform" in the
C standard.
....
>
> That's funny, indeed. What has POSIX to say of the access timestamp?
"The fgetc() function may mark the st_atime field of the file associated
with stream for update. The st_atime field shall be marked for update by
the first successful execution of fgetc(), fgets(), fgetwc(), fgetws(),
fread(), fscanf(), getc(), getchar(), gets(), or scanf() using stream
that returns data not supplied by a prior call to ungetc() or ungetwc()."