Technical questions regarding the xTIMEcomposer, xSOFTip Explorer and Programming with XMOS.
Active Member
Posts: 53
Joined: Fri Apr 15, 2016 6:46 pm


Postby DHembree » Wed Mar 21, 2018 5:18 am

In previous programming exploits I have used the following sample of code to manipulate individual bits in a byte-sized variable that would subsequently be written to a device (i2c):

union User_Switches_A
struct {
bool IN1_Sw :1; //
bool IN2_Sw :1; //
bool IN3_Sw :1; //
bool MON1_Sw :1; //
bool MON2_Sw :1; //
bool MON3_Sw :1; //
bool MUTE_L :1; //
bool MUTE_R :1; //
byte Byte;
} Switches_A;

The Xtime compiler does not like this. Is there any way to alter this to make it compatible with XC, or is there another method I can use to do the same task?

XCore Addict
Posts: 143
Joined: Fri Oct 23, 2015 10:23 am

Postby robertxmos » Wed Mar 21, 2018 9:17 am

Hi Dan,

Unfortunately for you the XC language does not support bit-fields or a 1-bit boolean type.
The work around is either to write your bit-field code in C/C++
or manually write access functions (which use bit wise operators).

The access functions may be in-lined, and hence produce similar code to if you had been allowed to express your intent directly.
Sorry for the extra layer of complexity that is necessary with both suggestions... unwelcome encapsulation & abstraction!


Who is online

Users browsing this forum: eapednic and 26 guests