<div dir="auto">It's hard to make things fool proof, fool's are too ingenius.  <div dir="auto"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Jul 2, 2018 6:14 PM, "Wolf" <<a href="mailto:wv99999@gmail.com">wv99999@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    <p>Not so long ago, Florian was proudly bragging about "Pascal does
      not allow you to <a href="http://www.toodarkpark.org/computers/humor/shoot-self-in-foot.html" target="_blank">shoot
        yourself in the foot</a>"</p>
    <p>What about this little program:</p>
    <p>program Project1;<br>
      <br>
      var a,b: byte;<br>
      begin<br>
        a:=1;<br>
        b:=a*(-1);<br>
        writeln(b);    // result: 255<br>
      end.<br>
          <br>
    </p>
    <p>The result is obviously correct, given how the variables are
      declared. But there are no compiler warnings / errors that the
      assignment b:=a*(-1) is fishy, to put it mildly. And if you are
      serious about strong typing, it ought to be illegal, with a
      suitable complaint from the compiler.</p>
    <p>Who is shooting whom in the foot?</p>
    <p>Wolf<br>
    </p>
    <br>
    <div class="m_2668105030677358280moz-cite-prefix">On 02/07/2018 20:22, Santiago A. wrote:<br>
    </div>
    <blockquote type="cite">El
      01/07/2018 a las 10:27, C Western escribió:
      <br>
      <blockquote type="cite">On 29/06/18 21:55, Sven Barth via
        fpc-pascal wrote:
        <br>
        <br>
        More confusingly, if a single variable is used, the expected
        Max(Double, Double) is called:
        <br>
        <br>
        function Max(a, b: Double): Double; overload;
        <br>
        begin
        <br>
          WriteLn('Double');
        <br>
          if a > b then Result := a else Result := b;
        <br>
        end;
        <br>
        <br>
        function Max(a, b: Single): Single; overload;
        <br>
        begin
        <br>
          WriteLn('Single');
        <br>
          if a > b then Result := a else Result := b;
        <br>
        end;
        <br>
        <br>
        var
        <br>
          v1: Double;
        <br>
          v2: Single;
        <br>
        begin
        <br>
          v1 := Pi;
        <br>
          v2 := 0;
        <br>
          WriteLn(v1);
        <br>
          WriteLn(Max(v1,0));
        <br>
          WriteLn(Max(v1,0.0));
        <br>
          WriteLn(Max(v1,v2));
        <br>
        end.
        <br>
        <br>
        Prints:
        <br>
         3.1415926535897931E+000
        <br>
        Single
        <br>
         3.141592741E+00
        <br>
        Double
        <br>
         3.1415926535897931E+000
        <br>
        Double
        <br>
         3.1415926535897931E+000
        <br>
        <br>
        If this is not a bug, it would be very helpful if the compiler
        could print a warning whenever a value is implicitly converted
        from double to single.
        <br>
      </blockquote>
      Well, pascal is a hard typed language, but not that hard in
      numeric issues. I think it is a little inconsistent that it
      implicitly converts '0.0' to double but '0 to single.
      <br>
      <br>
      Nevertheless, I think it is a bug. It doesn't choose the right
      overloaded function
      <br>
      <br>
      But the main is this:
      <br>
      you have several overload options for max
      <br>
      1 extended, extended
      <br>
      2 double, double
      <br>
      3 single, single
      <br>
      4 int64, int64
      <br>
      5 integer, integer
      <br>
      <br>
      When it finds (double, single), why does  it choose (single,
      single) instead of (double, double)?
      <br>
      The natural behavior should be to widen to the greater parameter,
      like it does in expressions.
      <br>
      <br>
    </blockquote>
    <br>
  </div>

<br>______________________________<wbr>_________________<br>
fpc-pascal maillist  -  <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.<wbr>org</a><br>
<a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal" rel="noreferrer" target="_blank">http://lists.freepascal.org/<wbr>cgi-bin/mailman/listinfo/fpc-<wbr>pascal</a><br></blockquote></div></div>