RE: Unsigned in Component Pascal

From: Treutwein Bernhard <"Treutwein>
Date: Mon, 17 Jun 2002 10:57:18 +0200

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

Hi Wojtek,

afaik, this is not (yet) a FAQ.

I guess that leaving out unsigned arithmetic was a deliberate
decision, although I also sometimes miss them.

The times of necessity to use variables, which are as small
as possible, seems to have vanished (except for embedded
systems).

Let me ask: Do you really need the aritmetic on BYTE ?

If you do not need it, this might be a solution:

MODULE PrivTest;
PROCEDURE TEST;
        VAR test:SHORTCHAR;
BEGIN
        test := 0ABX (*number too large*)
END TEST;
END PrivTest.

If you need them, I fear you'll have to use another
variable and do some conversion:

MODULE PrivTest;
PROCEDURE TEST*;
        VAR test:SHORTCHAR; number : SHORTINT;
BEGIN
        test := 0ABX (*number too large*);
        number := ORD(test);
        HALT(0)
END TEST;
END PrivTest.TEST

For arithmetic (?) with BYTE a word of caution:

VAR b : BYTE;
FOR b := MIN(BYTE) TO MAX(BYTE) DO SomeThing END;

is an endless loop, since overflow is silently wrapped
(this is absolutely correct, given the definition of
the FOR loop in terms of a WHILE loop.

VAR s : SHORTINT;
FOR s := MIN(BYTE) TO MAX(BYTE) DO SomeThing END;

works as expected.


> -----Original Message-----
> From: Wojtek Skulski [mailto:skulski{([at]})nowhere.xy
> Sent: Monday, June 17, 2002 5:43 AM
> To: BlackBox
> Cc: Wojtek Skulski
> Subject: Unsigned in Component Pascal
>
>
>
> Hi:
>
> this must be a FAQ, but let me ask. How can I treat
> a CP varaiable as an unsigned number, such that I can
> easily converse with C libraries?
>
> Specifically, the following does not compile with a message
> "number too large", even though it would fit as an unsigned
> bit pattern in the BYTE variable.
>
> Any idea how to make it compile without violating the "CP spirit"
> in some major way?
>
> MODULE TestTest;
> PROCEDURE TEST;
> VAR test:BYTE;
> BEGIN
> test := 0ABH (*number too large*)
> END TEST;
> END TestTest.
>
> As a side remark, lack of unsigned numerics in CP looks
> like a major pain to me. I did not realize this until started
> interfacing CP to Windows DLL's.
>
>
> Wojtek Skulski skulski{([at]})nowhere.xy
>
>
> --------------------------------------------
>
> To unsubscribe from this mailing list, send a message
> containing the word "unsubscribe" to:
> blackbox-request{([at]})nowhere.xy
>
> To get a list of valid e-mail commands and instructions on
> their usage, send a message containing the word "help" to the
> above address.
>
> Send any problem reports or questions related to this email
> list to the list owner at
> owner-blackbox{([at]})nowhere.xy
>
> Current posting policy:
>
> a) To post you should use the same address by which you are
> subscribed to the mailing list. That way, the list server
> will recognize you as subscriber and forward your posting
> immediately, without creating any overhead.
>
> b) If, for some reason, you cannot post from the address, by
> which you are subscribed, your message will be moderated to
> avoid spam. Please understand that moderation will often
> cause some delay, in particular over weekends or holydays.
>
--------------------------------------------

To unsubscribe from this mailing list, send a message containing the word "unsubscribe" to:
   blackbox-request{([at]})nowhere.xy

To get a list of valid e-mail commands and instructions on their usage, send a message containing the word "help" to the above address.

Send any problem reports or questions related to this email list to the list owner at
   owner-blackbox{([at]})nowhere.xy

Current posting policy:

a) To post you should use the same address by which you are subscribed to the mailing list. That way, the list server will recognize you as subscriber and forward your posting immediately, without creating any overhead.

b) If, for some reason, you cannot post from the address, by which you are subscribed, your message will be moderated to avoid spam. Please understand that moderation will often cause some delay, in particular over weekends or holydays.

----boundary-LibPST-iamunique-43315283_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"

e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5c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