In the section of the documentation on variables , it states the array type is "A list of whole numbers ranging from 0 to 255". In the array section, an array is described as "essentially a list of byte numbers". In the Dim keyword section, it states the syntax when used with arrays is Dim array(size) [At location]; i.e., no type specification is allowed.
All of this suggests arrays can only contain bytes.
And if I do this:
Dim test_array(5) As Word
test_array = 400,0,0,0,0
I get a compiler error: Error: Cannot store 400 in the byte variable POSTINC0
It compiles OK and test_array(1) will be 400 when printed over serial output.
A similar test works when the array type is Long and Integer, too.
I am assuming therefore that the documentation was written when arrays could only hold bytes, but this is no longer true--an array can hold any type within the limits of the device's RAM as long as values aren't assigned using a single-line statement. Is that correct?
`
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I would be very careful using this and would consider it "unsupported" until we can get an explanation from Anobium or Hugh. I doubt that someone forgot to update the help. I think it is more likely that there are specific reasons the Help does not address this.
There could be issues on small devices and if page boundaries are crossed. As a minimum precaution I might assign the array address at the start of a unused memory page in the case of an 18F chip and at the start of an 80 Byte block of GPR in the case of a 16F. And then make sure that the array is not so large that it could cross the boundary to the next page.
William
Last edit: William Roth 2021-05-20
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Why can't we dim arrays as strings ie dim data(5) as string : data(1)="hello" : data(2)="world" ?
Too complicated working length of string? Why not multi dimensioned arrays?
Pics now have more memory and the support old chips seems to restrict gcb with it's universal approach to ucontrollers.
I do know how to get around this but it ought to be standard commands ..imho.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The help is valid but seems out dated. It's been updated to use the 328p as a simple examples
probably cos they are popular.
A lot of it is pic only and when it refers to programmable pin chips gets complicated.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This is using RC45 (the newest release candidate available for Linux), compiled on a RPi3 using the latest version of FreeBasic.. I got the same result using RC38, too.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, it is mostly a documentation error. I will submit a pull request.
Before I do, how many bytes are required to store each element of an array composed of words, integers, or longs? I ask because the documentation currently states:
The limit on array size varies dependent on the chip type. The 12F/16F series of chips the array limit is 80 elements. For the Atmel AVR or an 18F there is no limit other than free RAM however Great Cow BASIC limits the array size to 10,000 elements. If a memory limit is reached, the compiler will give an error message.
I assume the 80 element lmit for 12F/16F chips is true for byte arrays, and would be less for other types?
Does the 10,000 element limit for 18F and AVR devices hold for arrays of other types, too?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Before I do, how many bytes are required to store each element of an array composed of words, integers, or longs? I ask because the documentation currently states:
Bytes - 1
Word - 2
Integers - 2
Long - 4
The limit on array size varies dependent on the chip type. The 12F/16F series of chips the array limit is 80 elements. For the Atmel AVR or an 18F there is no limit other than free RAM however Great Cow BASIC limits the array size to 10,000 elements. If a memory limit is reached, the compiler will give an error message.
Something better could be, please revise.
The limit on the array size varies dependent on the chip type, the amount of RAM and the number of other variable you use in your program.
Use the following simple program to determine the maximum array size. Set MAXSCOPE to a value which is less the total RAM. If the ARRAY does not fit reduce MAXSCOPE until the error message is not issued.
You MUST set the imaxvarialbe to suit the size of the constant MAXSCOPE.
It's good to know that arrays will hold variables bigger than byte (I've been splitting my words into a high and low byte arrays - don't suppose it makes much difference except for the extra programming). I also realize that the RAM banks on 16F chips are 80 bytes, but I have been regularly using larger byte arrays - so this limitation must have been circumvented some time ago.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
So If I understand correctly, setting the array elements via CSV line entries only supports byte sized elements. In other words this will continue to fail.
Method1 :
Dim MyArray(20 ) as WORD
MyArray = 1000, 2000, 3000, 4000
FAILS with Compiler Error
The ONLY way to put the elements in to Word, Integer, and Long arrays is like this.
Method 2:
Dim MyArray(20) as Word
MyArray(1) = 1000
MyArray(2) = 2000
MyArray(3) = 3000
MyArray(4) = 4000
It would seem to me that if Method 2 works with Word, Integer and Long elements then Method 1 could also be made to work similarly.
IMO this is more than just a Help File issue. This is a failure of a method that should work as expected.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You have added functionality to arrays but you still don't have a basic functionality that other languages have of array(0). It that because of backward compatibility? Why can't the zeroth element be used? and /or available?
Mike
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@mmotte It may be worth while doing empirical testing. Test across the range of chips (10f, 12f, 16f,18f and AVR) writing and testing to array element zero. Test using all types of array variables.
As I see it.,, empirical testing may reveal that byte array less than 255 elements are very different from larger byte arrays (because element zero cannot hold the array size!) and non-byte arrays are different from byte arrays.
The docs may be incorrect but it is worth empirical testing to get to the truth.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@Anobium I remember having this conversation a couple years back. It was explained to me that there is no zeroth element. But i have used it for programs. Not lately though.
Yes , testing
BR
Mike
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here's another example of using loc 0 for data. This code snippet will read the first block of Program Flash Memory into a Buffer (array) and then from the Buffer ... display it to a Terminal Application.
In the section of the documentation on variables , it states the
array
type is "A list of whole numbers ranging from 0 to 255". In the array section, anarray
is described as "essentially a list of byte numbers". In theDim
keyword section, it states the syntax when used with arrays isDim array(size) [At location]
; i.e., no type specification is allowed.All of this suggests arrays can only contain bytes.
And if I do this:
I get a compiler error:
Error: Cannot store 400 in the byte variable POSTINC0
But if I assign values to the array this way:
It compiles OK and test_array(1) will be 400 when printed over serial output.
A similar test works when the array type is
Long
andInteger
, too.I am assuming therefore that the documentation was written when arrays could only hold bytes, but this is no longer true--an array can hold any type within the limits of the device's RAM as long as values aren't assigned using a single-line statement. Is that correct?
`
There appears to be some undocumented support for Word, Integer and Long Variable arrays. I am using the latest release candidate ( RC47)
As you have seen this does not work:
However this seems to work OK.
I would be very careful using this and would consider it "unsupported" until we can get an explanation from Anobium or Hugh. I doubt that someone forgot to update the help. I think it is more likely that there are specific reasons the Help does not address this.
There could be issues on small devices and if page boundaries are crossed. As a minimum precaution I might assign the array address at the start of a unused memory page in the case of an 18F chip and at the start of an 80 Byte block of GPR in the case of a 16F. And then make sure that the array is not so large that it could cross the boundary to the next page.
William
Last edit: William Roth 2021-05-20
Why can't we dim arrays as strings ie dim data(5) as string : data(1)="hello" : data(2)="world" ?
Too complicated working length of string? Why not multi dimensioned arrays?
Pics now have more memory and the support old chips seems to restrict gcb with it's universal approach to ucontrollers.
I do know how to get around this but it ought to be standard commands ..imho.
The single-line assignment seems to be a problem when using types other than bytes for arrays. For instance, the following:
Gives this:
Oddly, if I blank the chip and remove the second assignments:
I now get this:
The help is valid but seems out dated. It's been updated to use the 328p as a simple examples
probably cos they are popular.
A lot of it is pic only and when it refers to programmable pin chips gets complicated.
Is this using RC47 ? As major changes have happened recently.
The RC47 is the baseline that we are using.
This is using RC45 (the newest release candidate available for Linux), compiled on a RPi3 using the latest version of FreeBasic.. I got the same result using RC38, too.
Is this just a documentation error ? If yes ( or no ) then the Help can be updated by anyone.
See https://github.com/Anobium/Great-Cow-BASIC-Help/tree/master/source and edit the source for others in the future. Even if this is an issue then updating the Help with help others in the future.
Yes, it is mostly a documentation error. I will submit a pull request.
Before I do, how many bytes are required to store each element of an array composed of words, integers, or longs? I ask because the documentation currently states:
I assume the 80 element lmit for 12F/16F chips is true for byte arrays, and would be less for other types?
Does the 10,000 element limit for 18F and AVR devices hold for arrays of other types, too?
Something better could be, please revise.
The limit on the array size varies dependent on the chip type, the amount of RAM and the number of other variable you use in your program.
Use the following simple program to determine the maximum array size. Set MAXSCOPE to a value which is less the total RAM. If the ARRAY does not fit reduce MAXSCOPE until the error message is not issued.
You MUST set the imaxvarialbe to suit the size of the constant MAXSCOPE.
For the Atmel AVR, LGT 328p or an 18F array sizes are limited to 10,000 elements.
If a memory limit is reached, the compiler will issue an error message.
Does the cover everything?
It's good to know that arrays will hold variables bigger than byte (I've been splitting my words into a high and low byte arrays - don't suppose it makes much difference except for the extra programming). I also realize that the RAM banks on 16F chips are 80 bytes, but I have been regularly using larger byte arrays - so this limitation must have been circumvented some time ago.
Thanks for the example code. That's very useful and helpful. I will include it in my changes.
Its worth noting that if you change the line:
to
the maximum array size MAXSCOPE that will compile without errors is halved from 111 to 55, as expected. For an array of longs, it's 27.
So If I understand correctly, setting the array elements via CSV line entries only supports byte sized elements. In other words this will continue to fail.
Method1 :
FAILS with Compiler Error
The ONLY way to put the elements in to Word, Integer, and Long arrays is like this.
Method 2:
It would seem to me that if Method 2 works with Word, Integer and Long elements then Method 1 could also be made to work similarly.
IMO this is more than just a Help File issue. This is a failure of a method that should work as expected.
@Jim Gregory
All your changes are published. See https://github.com/Anobium/Great-Cow-BASIC-Help/wiki
Huge Thank you!
No problem. Glad I could be of help!
You have added functionality to arrays but you still don't have a basic functionality that other languages have of array(0). It that because of backward compatibility? Why can't the zeroth element be used? and /or available?
Mike
@mmotte It may be worth while doing empirical testing. Test across the range of chips (10f, 12f, 16f,18f and AVR) writing and testing to array element zero. Test using all types of array variables.
As I see it.,, empirical testing may reveal that byte array less than 255 elements are very different from larger byte arrays (because element zero cannot hold the array size!) and non-byte arrays are different from byte arrays.
The docs may be incorrect but it is worth empirical testing to get to the truth.
@Anobium I remember having this conversation a couple years back. It was explained to me that there is no zeroth element. But i have used it for programs. Not lately though.
Yes , testing
BR
Mike
Testing and update the docs... as there is a zero element (this rules for usage) and things have changed over the years.
Please test using RC47. No point in testing any early version.
The zero element CAN be used. Just not when using the CSV line method of adding elements
Here is one way.
Last edit: William Roth 2021-05-25
Here's another example of using loc 0 for data. This code snippet will read the first block of Program Flash Memory into a Buffer (array) and then from the Buffer ... display it to a Terminal Application.
Last edit: William Roth 2021-05-25
I thought arrays were simple in gcb only they use ram.
I thought tables were simple in gcb and they are but use prog mem.
no probs with decent pic