aliasing word variables in reverse order?

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Gunplumber
Posts: 38
Joined: Wed Nov 02, 2022 10:31 am

aliasing word variables in reverse order?

Post by Gunplumber » Thu Nov 24, 2022 11:11 am

Hi Guys

I have question regarding aliasing word variables and the order of the bytes as they are stored..
I have an byte array that stores incoming serial data. The data is comprised of 16 bit words, but are sent MSB first then LSB. I am trying to alias the array to several word variables using the following code..

Code: Select all

Dim Array(10) as byte

Dim Word_var_1 as Array(0).Asword
Dim Word_var2 as Array(2).Asword
etc
However because the bytes are sent MSB-LSB, they are stored in the wrong order for the Aliasing (LSB then MSB) and any reference to my word variable is incorrect.

My first thought was just swapping the bytes as they are read and stored in the array, but i need the array in the order it was transmitted so i can preform a CRC check on the data. If i swap them, the CRC will never match and each packet will be rejected..

Other than going back through and swapping each pair using a separate routine is there any other way of doing it?

Cheers
Lee

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: aliasing word variables in reverse order?

Post by Jerry Messina » Thu Nov 24, 2022 1:50 pm

There's no way to get it to directly swap the byte order of the alias. You could use a function to read/write the bytes in swapped order for you, but that's not quite the same thing.

I think you're stuck doing it in code.

Post Reply