For instance, what is the output from this module?
Does the calculation overflow or not?
Hi,
On Sunday, October 22, 2017 at 2:13:19 AM UTC-5, August Karlstrom wrote:
For instance, what is the output from this module?
Does the calculation overflow or not?
Why don't you try it? What compilers do you use?
Oxford Oberon 3.0.7 (Win32) "obc -07" says "256" here (Win7 64-bit).
On 2017-10-21 19:33, August Karlstrom wrote:
As far as I understand, in Oberon-07 the types INTEGER and BYTE are expression compatible. But is the result of an arithmetic operation with
at least one BYTE operand always INTEGER?
For instance, what is the output from this module?
MODULE M;
IMPORT Out;
VAR
a, b: BYTE;
BEGIN
a := 255;
b := 1;
Out.Int(a + b, 0);
Out.Ln
END M.
Does the calculation overflow or not?
If you have to ask the question then you should avoid writing code like this. It would be just as risky as writing:
If two compilers differ, how do we know which one is correct and which
is not?
On Tuesday, October 24, 2017 at 1:14:13 PM UTC+2, cfbso...@gmail.com wrote:
If you have to ask the question then you should avoid writing code like this. It would be just as risky as writing:
Risky? Type-safe languages were invented for this reason.
On Sunday, October 22, 2017 at 5:43:19 PM UTC+10:30, August Karlstrom wrote:So you claim that for an expression containing a BYTE variable the
MODULE M;
IMPORT Out;
VAR
a, b: BYTE;
BEGIN
a := 255;
b := 1;
Out.Int(a + b, 0);
Out.Ln
END M.
Does the calculation overflow or not?
If you have to ask the question then you should avoid writing code like this.
Risky? Type-safe languages were invented for this reason.
The issue here is overflow detection not type safety.
So you claim that for an expression containing a BYTE variable the
result type is undefined?
From the report: "The type of the result is that operand's type which includes the other operand's type."
Which section of the report is that? I'm looking at Revision 1.10.2013 / 3.5.2016 and cannot see that statement.
So you claim that for an expression containing a BYTE variable the
result type is undefined?
On Wednesday, October 25, 2017 at 6:35:52 PM UTC+10:30, August Karlstrom wrote:
So you claim that for an expression containing a BYTE variable the
result type is undefined?
No. I'm saying that if *you*, as a programmer, are not convinced what the result should be then you should use a different approach that you are certain of. I see no good reason to use BYTE variables in calculations that expect INTEGER results.
On Wednesday, October 25, 2017 at 12:37:38 PM UTC+2, cfbso...@gmail.com wrote:
Which section of the report is that? I'm looking at Revision 1.10.2013 / 3.5.2016 and cannot see that statement.
Sorry, I clicked the old Oberon report by mistake.
Oberon-07 report says in 8.2.2. Arithmetic operators:
"Both operands must be of the same type, which is also the type of the result."
VAR
i1, i2, i3: INTEGER;
i1 := 2147483647;
i2 := 2147483645;
i3 := 10;
is i1 + i2 an INTEGER?
What this illustrates is that you should not make any assumptions about intermediate values of expressions when the behaviour is not explicitly stated and there is potential for overflow.
My question is not about arithmetic overflow. What I want to know is if
a + b is of type BYTE or INTEGER if a and b is of type BYTE.
Of course the expression i1 + i2 has type INTEGER. Arithmetic overflow
has nothing to do with this fact.
On Wednesday, October 25, 2017 at 10:30:25 PM UTC+10:30, August Karlstrom wrote:
Of course the expression i1 + i2 has type INTEGER. Arithmetic overflow
has nothing to do with this fact.
If it is 'of course' why then do you doubt that b1 + b2 has type BYTE? What does it matter what type it is if you don't care about overflow?
In my world the type of an expression is
determined by the type of its operands, not its value.
Because it could be the case that BYTE variables in expressions are implicitly converted to INTEGER. In fact, someone made that claim on the
ETH Oberon mailing list. In my world the type of an expression is
determined by the type of its operands, not its value.
Because it could be the case that BYTE variables in expressions are implicitly converted to INTEGER. In fact, someone made that claim on the
ETH Oberon mailing list. In my world the type of an expression is
determined by the type of its operands, not its value.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (0 / 16) |
Uptime: | 166:14:01 |
Calls: | 10,385 |
Calls today: | 2 |
Files: | 14,057 |
Messages: | 6,416,528 |