Undefined behaviour in C [was Re: The Cost of Dynamism]

BartC bc at freeuk.com
Sun Mar 27 07:31:26 EDT 2016


On 27/03/2016 07:34, Paul Rubin wrote:
> BartC <bc at freeuk.com> writes:
>>   But my suggestion was to have required a keyword in front of
>> such expressions.
>
> Should there be a keyword in front of a line containing "sqrt(x)" ?
> What about "launch(missiles)" ?

They both look like function calls. Function calls are *very* commonly 
used as standalone expressions.

You /could/ stipulate that they be written:

   call launch(missiles)    # like Fortran iirc

but that wouldn't be popular and is unnecessary.

> The compiler can't tell which of those expressions has a side effect.
> The first might be buggy code but the second is idiomatic.

Whether there are side-effects is not quite as important as picking up 
things that are likely to be errors:

   f()         # Probably OK
   g()         # Probably OK
   f()+g()     # Probably not OK

Maybe there is some legitimate, obscure reason for writing the latter, 
but stick some indicator in front to tell the language (and whoever 
happens to be reading the code) that this is what you intend.

In the case of sqrt(), many languages appear to treat maths operators as 
regular functions, so would be hard to justify special treatment. And in 
Python, 'sqrt' could be reassigned to do something different.

-- 
Bartc



More information about the Python-list mailing list