Andrzej Kocon <firstname.lastname@example.org> wrote:
On 1 Sep 2001 20:41:37 GMT, Wojtek Lerch <> email@example.com> > wrote:
Andrzej Kocon <> firstname.lastname@example.org> > wrote:
Although compilers should conform to the standards, this
style of coding is asking for trouble regardles of what the
standards might say about the meaning of such constructs…
I think you have it backwards. If the standard says that your code is
not correct C, it doesn’t matter whether you think it’s coded in a good
style. If your code produces undefined behaviour, it’s bad code even if
the compiler decides to generate something that that does what you
This is far more than can be concluded from my statement.
Um… I didn’t really say what exactly I concluded from your statement,
My interpretation of what you originally said was that as long as your
code meets your criteria of good coding, it doesn’t matter what the
language standard says about it. My response was that if the language
standard says that your code is invalid, it doesn’t matter whether it
meets your criteria. But as long as your criteria include the
requirement that your code must not be invalid, there’s no real conflict
between these two statements, is there…
You may safely restrain yourself from using certain programming
constructs, on any ground, without even referring to any standard.
Your criteria may be stronger than those implemented by the compiler.
Usually, your criteria should be stronger than those implemented by
the compiler. The fact that your code compiles and works in one
environment is not a proof that it doesn’t produce undefined behaviour.
And if it does, you never know when it may stop working (unless you
wrote your compiler and have no intention of using a different one…).
A famous one is “Does the construct simplify program reading, or
understanding, or (pardon) proving it correct?” (and it does not rely
entirely on one’s taste). This is not the job of a programmer to
ponder the niceties of doubtful or tricky language expressions, valid
or not (unless he writes… a compiler).
But it is!
The job of a programmer includes fixing broken code. You can try to do
that by replacing all the code that looks tricky or doubtful to you with
code that doesn’t look tricky or doubtful; the problem is that in some
cases, invalid code may not look tricky or doubtful, and in those cases,
it’s good to be able to recognize that it is invalid. And that’s when
understanding subtleties of the language can be useful.
Even if you choose to restrict yourself to using a subset of the
language that you feel is safer or easier to understand than the full
language, it still is a good idea to make sure that the subset indeed is
a subset. Before you can safely say that you can ignore the real limits
of the language because it’s enough for you to know the limits of your
subset, you have to make sure that your subset does not cross the real
limits. And that might sometimes be difficult if you don’t understand
the full language well enough.
Perhaps I should apologize for the term “style” which, besides
being too personal, might have encouraged the “backward” conclusion.
Then perhaps I should apologize for using such a strong word…
I didn’t recommend neglecting the language definition in favour of
I didn’t think you did – it would be against common sense, wouldn’t
Wojtek Lerch QNX Software Systems Ltd.