问题是这段代码不能用avr-g ++编译器编译。它会在标题中产生错误。当您注释掉第15行或第16行时,它将进行编译。如果从第15行和第16行的右侧删除''colourArray''或''blackArray'',它将编译。如果您将第15行和第16行中的''greyDiff'替换为变量赋值的相应右侧。如果它不在for循环中,它会编译。这不是编译器错误吗?
float colourArrayL[3] = {0, 0, 0};
float whiteArrayL[3] = {0, 0, 0};
float blackArrayL[3] = {0, 0, 0};
float colourArrayR[3] = {0, 0, 0};
float whiteArrayR[3] = {0, 0, 0};
float blackArrayR[3] = {0, 0, 0};
void setup()
{
for (byte i = 0; i < 3; i++)
{
float greyDiffL = whiteArrayL[i] - blackArrayL[i]; //the highest possible return minus the lowest returns the area for values in between
float greyDiffR = whiteArrayR[i] - blackArrayR[i];
colourArrayL[i] = (colourArrayL[i] - blackArrayL[i]) / greyDiffL;
colourArrayR[i] = (colourArrayR[i] - blackArrayR[i]) / greyDiffR;
}
}
void loop() {};
答案 0 :(得分:0)
我一直在使用avr-g ++(GCC)4.8.1,并且在为自定义类rgbscenario00编写复制构造函数时有类似的经验。在复制构造函数中复制超过5个rgbled对象时显示错误。我通过添加2个私有方法(使用divide&amp; conquer)解决了这个问题。所以似乎编译器试图使用所有寄存器,当它们全部被使用时,它就会因错误而停止。这是我的解决方案(仅显示重要部分:)
void rgbscenario00::copyrgb123( const rgbscenario00& orig ) {
magenta = orig.magenta;
rood = orig.rood;
geel = orig.geel;
}
void rgbscenario00::copyrgb456( const rgbscenario00& orig ) {
groen = orig.groen;
blauw = orig.blauw;
oranje = orig.oranje;
// uncommenting this last oranje line resulted in
// "error: unable to find a register to spill
// in class 'POINTER_REGS' "
}
rgbscenario00::rgbscenario00(const rgbscenario00& orig) {
// I have to split up this copy constructor to avoid
// getting a very silly error on the lack of registers
copyrgb123( orig );
copyrgb456( orig );
//magenta = orig.magenta; rood = orig.rood; geel = orig.geel;
//groen = orig.groen; blauw = orig.blauw;
//oranje = orig.oranje;
// uncommenting this oranje line resulted in
// "error: unable to find a register to spill
// in class 'POINTER_REGS' "
inputString = orig.inputString;
stringComplete = orig.stringComplete;
iteller = orig.iteller;
huedeviation = orig.huedeviation;
lumdeviation = orig.lumdeviation;
uiteller = orig.uiteller;
ujchosen = orig.ujchosen;
usbspeed = orig.usbspeed;
currentmillis = orig.currentmillis;
prevmillis = orig.prevmillis;
millisperloop = orig.millisperloop;
millisperstep = orig.millisperstep;
tfuture = orig.tfuture;
tstep = orig.tstep;
copyboolarray(&(computed[0]),&(orig.computed[0]),maxuirgblednum );
copyboolarray(&(done[0]), &(orig.done[0]), maxuirgblednum );
copyuliarray( &(nexttime[0]),&(orig.nexttime[0]),maxuirgblednum );
copyuiarray(&(uilumvalues[0]),&(orig.uilumvalues[0]),
maxuilumvalues );
}