DIM'ming an array

General discussion on mikroBasic PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
arco
Posts: 312
Joined: 15 Apr 2008 13:54
Location: The Netherlands

DIM'ming an array

#1 Post by arco » 03 Feb 2019 12:37

I have an array as buffer. I also want to split it into two for easy access.

Code: Select all

Dim DBuffer     As Char[1024]
    DBuffer_Lo  As Char[512] At DBuffer   
    DBuffer_Hi  As Char[512] At DBuffer[512]
For some reason the compiler acceps the DBuffer_Lo DIM, but not the DBuffer_Hi DIM [index]
Is there a workaround to do this?
Regards,

Peter.

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: DIM'ming an array

#2 Post by stefan.filipovic » 05 Feb 2019 12:37

Hi,

Unfortunately, you cannot use the keyword "at" in that way. After "at", the compiler expects the name of the variable, not the position in the array of chars, or the name of the register with access to individual bits in format (name).(bit number).

But you can do this in a few ways using pointers and strcpy function from String library.

With the use of "at" keyword:

Code: Select all

program test

dim DBuffer     as char[1024]
    DBuffer_Lo  as char[512] at DBuffer
    DBuffer_Hi  as ^char
main:
  DBuffer_Hi = @DBuffer + 512
  DBuffer_Lo = "TextLow"
  strcpy(DBuffer_Hi, "HighText")
end.
Without "at":

Code: Select all

program test

dim DBuffer as char[1024]
    ptr     as ^char

main:
 strcpy(DBuffer, "TextLow")
 ptr = @DBuffer + 512
 strcpy(ptr, "HighText")
end.
Kind regards,
Stefan Filipović

arco
Posts: 312
Joined: 15 Apr 2008 13:54
Location: The Netherlands

Re: DIM'ming an array

#3 Post by arco » 12 Feb 2019 17:20

Thanks,

That works...
Regards,

Peter.

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: DIM'ming an array

#4 Post by stefan.filipovic » 12 Feb 2019 17:55

Hi Peter,

You're welcome.

Kind regards,
Stefan Filipović

Post Reply

Return to “mikroBasic PRO for dsPIC30/33 and PIC24 General”