SiMessagePort payload->data_int: Wiki says 32bit data type but my Leonardo thinks an int should be 16bit.

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
lonespace
Posts: 64
Joined: Wed Mar 25, 2020 1:58 am

SiMessagePort payload->data_int: Wiki says 32bit data type but my Leonardo thinks an int should be 16bit.

#1 Post by lonespace »

1) Should I assign this to a long?
2) What should I use when I want to send only 16 bits (there’s no data type in the SiMessagePort constructor that is 16 bit)?
3) What happens if I try to assign a data_int (32 bit) to an int (16 bit)?

User avatar
Corjan
Posts: 2939
Joined: Thu Nov 19, 2015 9:04 am

Re: SiMessagePort payload->data_int: Wiki says 32bit data type but my Leonardo thinks an int should be 16bit.

#2 Post by Corjan »

Hi,


It is of type int32_t, so it is always 32 bits on all platforms.
Long is not a fixed type and can have a different size on different platforms. On Arduino a long is same as int32_t.

Changing from int16_t to int32_t is okay since a int32_t can store all numbers an int16_t can.
The other way around is also possible (with a cast or warning without), but note that you might loose data when your value doesn't fit in a int16_t.


Corjan


Post Reply