B
Bartc
Ben Bacarisse said:For those who haven't read it, Bartc is characterising the question so
as to make it look absurd. -1 < 5 is always 1 in C, and no relational
expression is ever "False" (I'm not sure what the significance of the
capital F is but it looks significant).
The expression was something like: (-1 < sizeof("test")), and it gave a
result of 0.
The problem is that sizeof("test") is 5u, not 5, which is the cause of the
trouble.
I am not sure, but I suspect that Eric's remark about "rash opinions" is
more likely to be about your suggestions for how C's mixed type
arithmetic should be done. I think it *is* rash to suggest how a
programming language should behave unless you know it very well indeed.
I don't think that is necessary. That have been plenty of proposals in this
group by people who cannot all have been experts in the language.
Just in case, here's mine again: the notion of common sense is not
applicable to programming languages, as this very thread shows. For
people who don't program but who have common sense in abundance, the
only response to seeing
i=0; i=++i+ ++i+ ++i;
should be to ask what that notation means. People who know one or two
languages in which that sequence of tokens has a well-defined meaning
would be most rash to assume it has the same meaning in another
language. To make such an assumption is not common sense -- it's the
opposite of common sense. Such people (coming from a C# and Java
background for example) may well have a deceptive expectation, but their
common sense should save them from it.
Try it yourself. What does this do:
f = (+1);
and is any language which does not match what your expectation flawed as
a result?
You've obviously got one in mind, perhaps some functional language, where
the above does something different.
The obvious guess, is that it sets f to the value 1 (and half-a-dozen
languages back me up). That would make my guess 'reasonable'.
Is there something about that syntax? The "=", "++" and "+" symbols of the
original example were fairly standard, and I would expect the "=", "+" and
"()" of yours to be the same.
(There has to be some set of programming constructions that are understood,
more-or-less, by everybody, otherwise there would be no such thing as
pseudo-code.)
And I didn't say C was flawed in that respect. I can understand exactly why
C doesn't like modifying the same thing several times in the same
expression; it would be a nightmare guaranteeing consistent, predictable
results. So it bans all such things, rather than allow certain simpler forms
to be well-defined.