Plse make 'external' consts usable in other 'external' defs

Post your requests and ideas on the future development of mikroPascal PRO for PIC.
Post Reply
Author
Message
Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Plse make 'external' consts usable in other 'external' defs

#1 Post by Dany » 24 Dec 2011 12:33

Please make 'external' constants usable in other 'external' constants definitions.

e.g. I would like to be possible:

Code: Select all

const ArraySize: byte; external;
const MyArray[ArraySize]: array of byte; external;// first external constant is already used here
Currently the second line gives a compiler error.

I have to use instead:

Code: Select all

const ArraySize: byte; external;
const MyArray[10]: array of byte; external; // here 10 is an arbitrary byte value
Above compiles well, but "SizeOf(MyArray)" always returns 10, irrespective of the actual size, so this function can not be used now on external constants.

Thanks in advance! :D :D
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: Plse make 'external' consts usable in other 'external' d

#2 Post by janko.kaljevic » 26 Dec 2011 17:16

Hello,

This implementation would require dynamic arrays and they must be in RAM. So there is no way to declare constant array like this.

Best regards.

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Plse make 'external' consts usable in other 'external' d

#3 Post by Dany » 26 Dec 2011 20:59

janko.kaljevic wrote:Hello,

This implementation would require dynamic arrays and they must be in RAM. So there is no way to declare constant array like this.

Best regards.
Ok, thanks! Keep up the good work! :D :D
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: Plse make 'external' consts usable in other 'external' d

#4 Post by janni » 27 Dec 2011 02:50

janko.kaljevic wrote:This implementation would require dynamic arrays and they must be in RAM. So there is no way to declare constant array like this.
This doesn't seem to be the problem here - all constants are available at compile time. Looking at present compiler possibilities, what Dany asks for is more change of notation, than something really new.
Please notice, that it doesn't matter what size of constant array is declared as external. The size is determined by the declaration in a parent unit/main and it cannot be any other way (if both sizes were to be taken into account, discrepancies would have to lead to an error, so it would be one size anyway).

One may already declare

Code: Select all

const ArraySize: byte; external;
const MyArray: array[1] of byte; external; // size given here is not decisive
and, in the parent unit

Code: Select all

const ArraySize=5;
const MyArray: array[ArraySize] of byte=(0,1,2,3,4);
which in effect produces constant array of 5 elements. And one may now use ArraySize as size of MyArray in the child unit, though it would be better if SizeOf could produce valid result, as well.

The notation proposed by Dany

Code: Select all

const ArraySize: byte; external;
const MyArray: array[ArraySize] of byte; external;
is actually showing a way for easy implementation of proper operation of SizeOf in such cases. (Naturally, in some future, SizeOf should produce valid results, whatever the notation, and there should be no need to provide sizes with no real meaning in external declarations.)

Post Reply

Return to “mikroPascal PRO for PIC Wish List”