Jump to content
Excelsior Forums
Sign in to follow this  
yup

Max. size of type

Recommended Posts

Can anybody satisfy my curiosity:

Why max. size of type is MAX(CARDINAL)/2 - 1 and not MAX(CARDINAL)+1  (or just MAX(CARDINAL))  as one may expect?

(For example, it is not possible to declare neither

TYPE String = ARRAY CARDINAL OF CHAR;

nor

TYPE String = ARRAY [0..MAX(CARDINAL) DIV 2] OF CHAR;

but

TYPE String = ARRAY [0..MAX(CARDINAL) DIV 2 - 1] OF CHAR;

is acceptable definition.)

I am not asking about variables; size of type - what is limited.

Share this post


Link to post
Share on other sites

I surmised this. But what was a reason to use an integer variable for calculation of value known to be non-negative? - It's still my curiosity (or education, maybe :-).

Share this post


Link to post
Share on other sites

Because you may wish to assign the result of SIZE() to an INTEGER variable or pass it to a parameter of type INTEGER, and so on.

In short, this makes life easier. :)

Share this post


Link to post
Share on other sites

Because you may wish to assign the result of SIZE() to an INTEGER variable or pass it to a parameter of type INTEGER, and so on.

But compiler does not apply this limitation for 16 bit base types: when M2BASE16 option is ON, all the above mentioned definitions are allowed. Is it a compiler bug or just an inconsistency? ;-)

Share this post


Link to post
Share on other sites

Yes, I have. But initial sentence was unambiguous: "must fit into INTEGER".

As a mathematician and an old Modula-2 programmer I treat your words literally: if you said "a luminium", then it is a luminium.

And aside note (without any jokes): if _calculations_ appear on a scene (not just assignments), then any artifical limitations are pointless - one may define a type ARRAY [1..2048] OF CARD8, and then want to calculate a total size of 2000000 of such arrays.

Share this post


Link to post
Share on other sites

Unfortunately, I cannot research this academic question further at this time, as the respective engineers are very busy getting Excelsior JET 4.5 ready for release. Let's say for now that it is a limitation of our implementation.

Share this post


Link to post
Share on other sites

A question in the first message was pure academical, but the last message was rather practical. And yes - I treated your answer exactly as you said: "a limitation of implementation".

But taking into account that development of compiler is closed, I did not expect so vivid reaction in your last answer. Or there is a hope?

Share this post


Link to post
Share on other sites

Ok. I am stopping to bother you with this abstract topic - I have a more important question instead (in another thread).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×