Forum > General

Please explain how this operator overloading works.

<< < (2/5) > >>

That is why we implemented it like you expect! But it is not correct.

And my answer was more to his Question, why q:=1 results in a random value

Ah, just replace mod with a shr 4 will do. Probably sar for signed. Not tested.

Nibbles in computer science can be either 4 bits or half the size of any integer signed or not, depending on the context. As an example, in the Intel x86 architecture, nibbles are defined as 4 bits, while in the ARM architecture, nibbles are defined as half the size of any integer signed or not.


1. IntelĀ® 64 and IA-32 Architectures Software Developer's Manual Volume 1: Basic Architecture, Intel, 2017.
2. ARM Architecture Reference Manual, ARM, 2012.
3. The term itself was introduced in 1965 by John G. Kemeny in 1965, who was wrong because it already existed under different names all the way back to Boole himself.

Note that 2. is theoretically correct and how I learned it many moons ago. 1. is just how it is now defined in practice, but an error. I have implemented an intentional error in sysutils...
Mea Culpa.  :'(

Anyway: as long as there is a definition for a purpose it is legal. That does not mean it is logically correct of course.


--- Quote from: Zvoni on February 02, 2023, 09:47:17 am ---And my answer was more to his Question, why q:=1 results in a random value

--- End quote ---

No, you've misunderstood.

--- Quote from: Zvoni on February 02, 2023, 09:16:18 am ---
--- Quote from: JustAQuestion on February 02, 2023, 08:13:57 am ---
As is, the output is 1 and 7.
With the '??', the first result is seemingly random, the second is 7.

--- End quote ---
Your first call (q:=1) has no Result set in the Operator

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Operator := (src : Byte) : TNibble;Begin        // writeln('??');        if src > 15 then Result._Nibble:= src mod 16 Else Result._Nibble:=42;End;
--- End quote ---

--- Quote ---What is also interesting is that, when I remove the // from the first writeln, I get a random result at first, but the second result is correct anyway.
--- End quote ---

It worked without setting the result, which doesn't seem to make sense.

The *WriteLn* caused the random result.
When I comment it away, the number is correct.

Do you have an explanation? Generally it seems that this should not work at all, yet it does.


[0] Message Index

[#] Next page

[*] Previous page

Go to full version