Re: [BLACKBOX] [Fwd: Re: [BLACKBOX] Another trap during compile]

From: [at]} <Chris>
Date: Fri, 22 Oct 2010 09:02:18 +1030

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

>-----Original Message-----
>From: BlackBox [mailto:BLACKBOX{([at]})nowhere.xy
>Oleg N. Cher
>Sent: Thursday, 21 October 2010 7:55 PM
>To: BLACKBOX{([at]})nowhere.xy
>Subject: [BLACKBOX] [Fwd: Re: [BLACKBOX] Another trap during compile]
>
>And what you think about real code, that looks so:
>
>MODULE XGrSettings;
>
>TYPE
> ScreenDepthBits8 = BYTE;
> ScreenDepthBits16 = SHORTINT;
> ScreenDepthBits32 = INTEGER;
> Color* = ScreenDepthBits8;
>
> ...
>
>END XGrSettings.
>
>PROCEDURE RGB* (r, g, b: SHORTCHAR): Color; BEGIN RETURN
>SYSTEM.VAL(Color, Sdl.MapRGB(screen.format,
> SYSTEM.VAL(UInt8, r), SYSTEM.VAL(UInt8, g),
>SYSTEM.VAL(UInt8, b))) END RGB;
>
>Probably you agree what optional set screen deep as type in
>module Settings is a good way. And if I want to do it in this
>way, I need type casting with type Color which has variable size.
>

Difficult to say as I'm not familiar with the SDL library, I don't know what
your design requirements are, how UInt8 is defined, and I can't tell how
you're using ScreenDepthBits.

In the old days, when I was using Pascal and Modula-2 I used to go overboard
and create a different type for just about every scalar variable I used.
More often than not I'd end up falling into a hole that I'd dug for myself.
I get the feeling the same is happening to you. Nowadays, when using Oberon
I use INTEGER for most integral variables and depend on the use of
assertions to handle range-checking. Most of my user-defined types tend to
be structures.

You should only use SYSTEM.VAL when absolutely necessary. All it does is
bypass type-checking so if you do use it you are defeating one of the
reasons for creating a set of different types.

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.

Regards,
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-888935123_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwID4tLS0tLU9yaWdpbmFsIE1lc3NhZ2UtLS0tLVxw
YXINCj5Gcm9tOiBCbGFja0JveCBbbWFpbHRvOkJMQUNLQk9YQExJU1RTLk9CRVJPTi5DSF0gT24g
QmVoYWxmIE9mIFxwYXINCj5PbGVnIE4uIENoZXJccGFyDQo+U2VudDogVGh1cnNkYXksIDIxIE9j
dG9iZXIgMjAxMCA3OjU1IFBNXHBhcg0KPlRvOiBCTEFDS0JPWEBMSVNUUy5PQkVST04uQ0hccGFy
DQo+U3ViamVjdDogW0JMQUNLQk9YXSBbRndkOiBSZTogW0JMQUNLQk9YXSBBbm90aGVyIHRyYXAg
ZHVyaW5nIGNvbXBpbGVdXHBhcg0KPlxwYXINCj5BbmQgd2hhdCB5b3UgdGhpbmsgYWJvdXQgcmVh
bCBjb2RlLCB0aGF0IGxvb2tzIHNvOlxwYXINCj5ccGFyDQo+TU9EVUxFIFhHclNldHRpbmdzO1xw
YXINCj5ccGFyDQo+VFlQRVxwYXINCj4gU2NyZWVuRGVwdGhCaXRzOCAgPSBCWVRFO1xwYXINCj4g
U2NyZWVuRGVwdGhCaXRzMTYgPSBTSE9SVElOVDtccGFyDQo+IFNjcmVlbkRlcHRoQml0czMy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HlvdSBzaG91bGQgdXNlIHRoZSBidWls
dC1pbiBwcm9jZWR1cmVzIExPTkdccGFyDQphbmQgU0hPUlQgdG8gY29udmVydCBmcm9tIG9uZSB0
eXBlIHRvIGFub3RoZXIuIFxwYXINClxwYXINClJlZ2FyZHMsXHBhcg0KQ2hyaXMgQnVycm93c1xw
YXINCkNGQiBTb2Z0d2FyZVxwYXINCmh0dHA6Ly93d3cuY2Zic29mdHdhcmUuY29tXHBhcg0KXHBh
cg0KXHBhcg0KLS0tLVxwYXINClRvIHVuc3Vic2NyaWJlLCBzZW5kIGEgbWVzc2FnZSB3aXRoIGJv
ZHkgIlNJR05PRkYgQkxBQ0tCT1giIHRvIExJU1RTRVJWQExJU1RTLk9CRVJPTi5DSFx9fQBST04=
----boundary-LibPST-iamunique-888935123_-_---
Received on Fri Oct 22 2010 - 00:32:18 UTC

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