Misusage of "char" type in USB example.

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:

Misusage of "char" type in USB example.

#1 Post by Dany » 09 Mar 2012 16:14

Hi, in the example "C:\Users\Public\Documents\Mikroelektronika\mikroPascal PRO for PIC\Examples\Development Systems\EASYPIC7\USB\HID Read Write Interrupt" i see the following in the UsbDsc.mpas file:

Code: Select all

...
const USB_HID_RPT_SIZE : char = 33; // 33 bytes! is the correct size
...
...

type hid_report_descriptor = record
  report : array[USB_HID_RPT_SIZE] of char; // <------------------
end;

const hid_rpt_desc : hid_report_descriptor = (
...
In the marked line the array is of type "char", making the constant "hid_rpt_desc" 34 bytes long instead of 33 (an extra zero is added). Better to use a "byte" here, the array is no "string". It could go wrong if e.g. the usb library used "SizeOf(hid_rpt_desc)".

Also valid for the P24 mP example.

If I am not mistaking this is a difference with mC: in the latter an array of 10 chars is 10 bytes long, in mP an array of 10 chars is 11 bytes long. Why is this difference there?
Last edited by Dany on 02 Jun 2012 18:35, edited 1 time in total.
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: Misusage of "char" type in USB example.

#2 Post by janko.kaljevic » 12 Mar 2012 18:02

Hello Danny,

You are right regarding this matter.
It should be declared as byte type.

Thanks for reporting we will fix it as soon as possible.

Best regards.

Post Reply

Return to “mikroPascal PRO for PIC Beta Testing”