[?]v1.40-2.50: Constant declarations issue

Beta Testing discussion on mikroPascal PRO for PIC.
Post Reply
Author
Message
Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

[?]v1.40-2.50: Constant declarations issue

#1 Post by Dany » 05 May 2009 13:34

Hi, I see some odd things when using "SizeOf" and "Hi"/"Lo" together with typecasting in constant declarations. As far as I can test the problem does not occur when the destination is a variable.

The following declarations work OK (meaning the content of Config1 is "1000" if interpreted as word):

Code: Select all

const ReportDescriptor: array[1000] of byte = (
    0x06, 
    0xA0
    // ....
);
const Config1 : array[2] of byte = (
    Lo(SizeOf(ReportDescriptor)),
    Hi(SizeOf(ReportDescriptor))
);
The code below is not OK, the content of Config1 is zero (both bytes, while they should contain "1000" if interpreted as a word):

Code: Select all

const ReportDescriptor: array[1000] of byte = (
    0x06, 
    0xA0
    // ....
);
const Config1 : array[2] of byte = (
    Lo(word(SizeOf(ReportDescriptor))), // <-------- typecast
    Hi(word(SizeOf(ReportDescriptor)))  // <-------- typecast
);
Listfile extract:

Code: Select all

;HiLo.mpas,16 :: _Config2
0x04AA        0x0000 ;_Config2+0
; end of _Config2
;HiLo.mpas,11 :: _Config1
0x04AC        0x03E8 ;_Config1+0
; end of _Config1
I do need the typecast because following code gives a compilation error (and I would like to make my code independant of the size of an object like "ReportDescriptor"):

Code: Select all

const ReportDescriptor: array[50] of byte = ( // <--- value <256 now
    0x06, 
    0xA0
    // ....
);
const Config1 : array[2] of byte = (
    Lo(SizeOf(ReportDescriptor)), 
    Hi(SizeOf(ReportDescriptor))  // <-------- compilation error
);
see http://www.mikroe.com/forum/viewtopic.php?t=19839.

Thanks in advance!
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)

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

#2 Post by Dany » 22 Sep 2009 20:33

Situation has changed with the v3.00 bèta version:
"Hi" for values < 256 give still an error. The second definition "Config1" now gives a "Bad aggregate definition" compiler error.

Comment fro mE:
Hi() is forbidden for RAM variables which are less than two bytes. However, we shall allow this for consts, there is no reason for forbidding it.
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
srdjan
mikroElektronika team
Posts: 1552
Joined: 28 Dec 2005 12:47
Location: Serbia

#3 Post by srdjan » 13 Oct 2009 08:13

Hi,
hi, higher, highest now allowed for constants with less bytes.

This:

Code: Select all

const ReportDescriptor: array[1000] of byte = (
    0x06,
    0xA0
    // ....
);
const Config1 : array[2] of byte = (
    Lo(word(SizeOf(ReportDescriptor))), // <-------- typecast
    Hi(word(SizeOf(ReportDescriptor)))  // <-------- typecast
);
Will remain as bug for now, since release is coming this week.
Thanks.

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

#4 Post by Dany » 13 Oct 2009 09:32

Thanks! :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)

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

#5 Post by Dany » 17 Oct 2009 20:53

Hi,

in mP v3.20 the "Bad aggregation definition"compiler error is gone :D , and the function "Hi" does not give any longer a compiler error in constructions as below in Config3 :D ,
but the second version of Config1 (see config2 below) gives a wrong result :cry: :

Code: Select all

program HiLo;

{ Declarations section }

const ReportDescriptor: array[1000] of byte = (
    0x06,                    // USAGE_PAGE (Vendor Defined)
    0xA0
    // ....
);

const Config1 : array[2] of byte = (
    Lo(SizeOf(ReportDescriptor)),
    Hi(SizeOf(ReportDescriptor))
);

const Config2 : array[2] of byte = (
    Lo(word(SizeOf(ReportDescriptor))),
    Hi(word(SizeOf(ReportDescriptor)))
);


const TestDescriptor : array[255] of byte = (1,2,3);

const Config3 : array[2] of byte = (
    Lo(SizeOf(TestDescriptor)),
    Hi(SizeOf(TestDescriptor))
);


type TBufferDescriptor =
     record
       Status: byte;
       ByteCount: byte;
       Address: word;
     end;

const P2: ^byte;

begin
  { Main program }

  P2 := @Config1;
  P2 := @Config2;
  P2 := @Config3;

end.
Content of the listfile:

Code: Select all

;HiLo.mpas,24 :: _Config3
0x0529	0x00FF ;_Config3+0               <-- correct
; end of _Config3
;HiLo.mpas,16 :: _Config2
0x052B	0x0201 ;_Config2+0               <-- should be 0x03E8 :cry: 
; end of _Config2
;HiLo.mpas,11 :: _Config1
0x052D	0x03E8 ;_Config1+0               <-- correct
; end of _Config1
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
srdjan
mikroElektronika team
Posts: 1552
Joined: 28 Dec 2005 12:47
Location: Serbia

#6 Post by srdjan » 17 Oct 2009 21:43

I'll just quote myself:
srdjan wrote:Hi,
hi, higher, highest now allowed for constants with less bytes.

This:

Code: Select all

const ReportDescriptor: array[1000] of byte = (
    0x06,
    0xA0
    // ....
);
const Config1 : array[2] of byte = (
    Lo(word(SizeOf(ReportDescriptor))), // <-------- typecast
    Hi(word(SizeOf(ReportDescriptor)))  // <-------- typecast
);
Will remain as bug for now, since release is coming this week.
Thanks.

Post Reply

Return to “mikroPascal PRO for PIC Beta Testing”