News:

Let's find out together what makes a PIC Tick!

Main Menu

Aliasing bits in an array

Started by Simon, Apr 21, 2021, 08:22 AM

Previous topic - Next topic

Simon

It would be useful for me to be able to give the bits in an array meaningful names to make the code more readable but although I can do it for a byte it doesn't compile for a byte in an array.

I would have thought this should work so maybe I'm doing something wrong??

Dim myByte As Byte = 8
Symbol myBit = myByte.3    'works as expected



Dim myArray[4] As Byte
Symbol myOtherBit = myArray[2].6     'does not compile


Yasin

#1
You should do as in the example.

Dim myByteArray[8] As Byte
Dim myByteArray1 As myByteArray#2

Symbol myOtherBit = myByteArray1.6

Simon

I'd not seen that before.

For anyone else looking it's under "Finer points of array variables" in the manual and is actually an underscore for P24.

Many thanks Yasin

Simon

.... also I think you can just do myOtherBit = myByteArray_1.6 without creating the dummy byte, at least it compiles ok

top204

#4
I had to use an underscore instead of a hash '#' in Proton24 because the GCC C30 assembler does not allow a hash in symbol's name.

The same will be with the new GCC assembler required for Positron8 for the new 8-bit devices, but I will be trying my damnest to keep the hash in the BASIC code, then change it to an underscore wnen the assembler code is created, so it will maintain backward compatability.

When I first created the compilers, I was determined not to waste the elements in an array as other compilers do, so I made each element into a variable in its own right, so every element of an array can be accessed individually if required.