Re: [BLACKBOX] Conversion & Casting

From: [at]} <Chris>
Date: Tue, 26 Oct 2010 09:46:16 +1030

----boundary-LibPST-iamunique-1192965569_-_-
Content-type: text/plain

>-----Original Message-----
>From: BlackBox [mailto:BLACKBOX{([at]})nowhere.xy
>Sent: Tuesday, 26 October 2010 7:41 AM
>To: BLACKBOX{([at]})nowhere.xy
>Subject: [BLACKBOX] Conversion & Casting
>
>On 21/10/2010 23:32, Chris Burrows wrote:
>
>> If what you actually need is type *conversion* (for types of
>different
>> size) rather than type *casting* then you should use the built-in

>> procedures LONG and SHORT to convert from one type to another.
>
>
>Folks, I am rather confused by recent posts because I don't
>really understand the jargon.
>

You're not the only one who is confused. I thought I understood it until
Oleg started talking about type casting with different data sizes.

>
>Does (*conversion*) mean using different bit patterns too
>represent the same 'idea'?
>For example the idea "-3" might be represented as C008 0000
>0000 0000 as a REAL,
>as FFFF FFFF FFFF FFFD as a LONGINT, as FFFF FFFD as an
>INTEGER, and so on. Such
>transformations would use SHORT, LONG, ENTIER and implicit conversions.
>

That is certainly what I understood it to mean.

>
>Does (*casting*) mean using the same bit pattern to represent
>different ideas?
>For example FFFF FFFD would represent -3 as an INTEGER and {0,
>2..31} as a SET.
>Such transformations would ideally use functions such as BITS
>& ORD, but would
>need SYSTEM.VAL when the CP language did not give explicit
>support (eg from
>POINTER to INTEGER)?
>

That is certainly what I understood it to mean. The main difference is that
SYSTEM features are explicitly defined to be non-portable so using VAL is
guaranteed to be implementation-dependent. Any similarity with results on
other systems is purely coincidental.

>
>What (*should*) SYSTEM.VAL do when the input and output have
>differing numbers
>of bits (which seems to be the case in recent discussions)?
>

A very good question. I would like to think it would give a compile-time
error at best or a runtime-error at worst. However, SYSTEM features are
intentional loopholes and have little or no protection mechanisms built-in.
It is assumed that the programmer knows what he is doing is dangerous but
wants to do it anyway. I guess if you deliberately put a gate in a fence on
the top of a cliff there's not much point putting a sign up saying 'Don't
walk through this gate'.

>
>What (*does*) SYSTEM.VAL do when the input and output have
>differing numbers of
>bits?
>

I did a quick test and found that BlackBox happily compiles and runs
something like the following:

TYPE
  String = ARRAY 256 OF CHAR;

VAR
  s: String;
  i: INTEGER;
...
...
  s := '123';
  i := SYSTEM.VAL(INTEGER, s);

The resulting value of i is 00320031H so it looks like it's just typecast
the first corresponding number of bits.

I've made a mental note to be even more careful in future when using
SYSTEM.VAL ;-)

Regards,
Chris

Chris Burrows
CFB Software
http://www.cfbsoftware.com


----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-1192965569_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwID4tLS0tLU9yaWdpbmFsIE1lc3NhZ2UtLS0tLVxw
YXINCj5Gcm9tOiBCbGFja0JveCBbbWFpbHRvOkJMQUNLQk9YQExJU1RTLk9CRVJPTi5DSF0gT24g
QmVoYWxmIE9mIFJvYmVydFxwYXINCj5TZW50OiBUdWVzZGF5LCAyNiBPY3RvYmVyIDIwMTAgNzo0
MSBBTVxwYXINCj5UbzogQkxBQ0tCT1hATElTVFMuT0JFUk9OLkNIXHBhcg0KPlN1YmplY3Q6IFtC
TEFDS0JPWF0gQ29udmVyc2lvbiAmIENhc3RpbmdccGFyDQo+XHBhcg0KPk9uIDIxLzEwLzIwMTAg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ClxwYXINClxwYXINCi0tLS1ccGFyDQpUbyB1bnN1YnNjcmliZSwgc2Vu
ZCBhIG1lc3NhZ2Ugd2l0aCBib2R5ICJTSUdOT0ZGIEJMQUNLQk9YIiB0byBMSVNUU0VSVkBMSVNU
Uy5PQkVST04uQ0hccGFyDQp9
----boundary-LibPST-iamunique-1192965569_-_---
Received on Tue Oct 26 2010 - 01:16:16 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:30:29 UTC