On Friday, 21 September 2018 17:19:36 UTC+3, bitrex wrote:
> On 09/20/2018 02:21 AM, David Brown wrote:
> > On 20/09/18 01:47, bitrex wrote:
> >> On 09/19/2018 05:23 PM, David Brown wrote:
> >>> On 19/09/18 19:43, bitrex wrote:
> >>>> On 09/19/2018 12:23 PM, Scott wrote:
> >>>>> On Wed, 19 Sep 2018 11:01:45 -0400, "Rick C. Hodgin"
> >>>>> <
rick.c...@gmail.com> wrote:
> >>>>>
> >>>>>> Can anyone think of a reason why this type of operation shouldn't
> >>>>>> be a valid syntax in a (C/C++)-like lanuage, added to that new
> >>>>>> language with these features:
> >>>>>>
> >>>>>> if (a <= b < c)
> >>>>>> printf("b is [a, c)\n");
> >>>>>>
> >>>>>> if (a < b <= c)
> >>>>>> printf("b is (a, c]\n");
> >>>>>>
> >>>>>> if (a < b < c)
> >>>>>> printf("b is (a, c)\n");
> >>>>>>
> >>>>>> And even these:
> >>>>>>
> >>>>>> if (a < b < c < d)
> >>>>>> prinf("b is (a, c)\nc is (b, d)\n");
> >>>>>>
> >>>>>> if (a < b < c < d < e)
> >>>>>> prinf("b is (a, c)\nc is (b, d)\nd is (c, e)\n");
> >>>>> ...
> >>>>>
> >>>>> What nonsense are you trolling about now? Everybody knows that these
> >>>>> are already perfectly valid constructs in C with simple and
> >>>>> unambiguous semantics.
> >>>>>
> >>>>
> >>>> it's ambiguous enough in that gcc emits a warning:
> >>>
> >>> gcc does not give a warning because it is ambiguous - the code is not
> >>> ambiguous in C. gcc gives a warning because it is probably incorrect
> >>> code.
> >>>
> >>> There is nothing wrong with the idea of making expressions like these
> >>> match their mathematical meaning. But it would be confusing to do so
> >>> in a C-like language.
> >>
> >> Yes, I meant "ambiguous" in the sense of my brain might not have been
> >> able to immediately intuit what behavior that form of expression
> >> invoked. Given that it compiled and it does not appear to invoke any
> >> undefined behavior I know of then surely the compiler is not confused.
> >> It will do something, whatever it is.
> >
> > Ah, you mean /your/ interpretation of it is ambiguous - not that the C
> > itself is ambiguous. Yes, I can appreciate that. There is nothing for
> > it but to learn the way C interprets this type of expression - and then,
> > like all sane C programmers, avoid writing it.
>
> I've been writing C/C++ off and on since ALL THE WAY BACK in the late
> 1990s and I can't say it ever occurred to me to write a test like if ( a
> < b < c ) I'd probably just write (a < b && b < c) by force of habit.
> the former is very high-school math-y vs. Boolean logic.
Note that the '(a < b && b < c)' is likely sub-optimal code when
those are integer or pointer values and it is meant as a check if
that 'b' is inside of some fixed range 'a' to 'c' (that is quite
frequent purpose of that expression). Issue is that implementations
tend to generate two branches there. Sometimes these are generated
even when the a and c are known compile time. Branches are quite
expensive on modern out-of-order hardware.