[Oberon] Type conversion.
peter at easthope.ca
peter at easthope.ca
Wed Jul 5 19:08:28 CEST 2023
From: Joerg <joerg.straube at iaeth.ch>
Date: Tue, 4 Jul 2023 23:41:20 +0200
> If the remPort was signed16, I strongly assume locPort was signed16
> as well.
The details make a long story but a worthwhile exercise for non-expert
me and may interest others.
Oberon.Mail.Mod has NetTools.Connect(S.C, port, host, FALSE)
S is a NetTools.Session
port is SIGNED16.
Oberon.NetTools.Mod has
Connect*(VAR C: NetSystem.Connection; port: UNSIGNED16; host: ARRAY OF CHAR; log: BOOLEAN): BOOLEAN;
Conversion of port, SIGNED16, to UNSIGNED16 allows substitution of port.
Also,
MODULE NetSystem IN Oberon;
CONST
...
(* any port value *)
anyport* = 0;
Furthermore,
NetTools.Connect invokes,
NetSystem.OpenConnection(C, NetSystem.anyport, adr, port, res)
Unix.Oberon.NetSystem.Mod has
OpenConnection* ( VAR conn: Connection; locPort: UNSIGNED16; remIP: IPAdr; remPort: UNSIGNED16;
VAR res: SIGNED16 );
...
conn.Open( locPort, remIP, remPort MOD 10000H, r );
Types of the first and third parameters are in question.
Conversion of 0 to UNSIGNED16 is valid. Therefore substitution of anyport into locPort is OK.
Substitution of port, UNSIGNED16, into remPort, UNSIGNED16, requires no conversion.
conn is a Connection which is a TCP.Connection.
IMPORT ... TCP := TCP IN A2 ...
In TCP.Mod,
TYPE (** Connection object.
...
PROCEDURE Open*(lport: UNSIGNED32; fip: IP.Adr; fport: UNSIGNED32; VAR res: INTEGER);
Conversion UNSIGNED16 -> UNSIGNED32 allows both substitutions.
Two details still interest me.
(1) ETH Oberon (2019) Language Report, page 21, Figure 7.2 "Integer
Compatibilities" shows the various conversions. The compiler might be
able to find a multi-step conversion. Eg. Thee are two paths
SIGNED16 -> UNSIGNED32.
(2) TCP := TCP IN A2. Why alias a module name to itself? Why not
just TCP IN A2?
From: Joerg <joerg.straube at iaeth.ch>
Date: Sun, 2 Jul 2023 17:51:37 +0200
> I canât answer the question, why the author of this source code uses
> âremPortâ with an explicit conversion and âlocPortâ with the
> implicit conversion, the compiler generates.
Hypothetical possibility: in earlier source, locPort and remPort had
different types and explicit conversion was applied. Subsequently
locPort was revised. Inadvertently, remPort was left with explicit
conversion LONG(remPort). An inadvertent divergent revision. Such
things also happened in more traditional engineering disciplines.
Auditing can find anomalies.
Thanks for the help, ... P.L.
-
mobile: +1 778 951 5147
VoIP: +1 604 670 0140
More information about the Oberon
mailing list