我有下面的功能,该功能似乎应有的作用,但是通过测试程序运行该程序时,出现错误:解析错误:[int xSwapped =((255 未声明的变量`xSwapped':[返回(〜xSwapped&x)| nMask | mMask;]int dl15(int x, int n, int m){ // calculates shifts, create mask to shift, combine result // get number of bytes needed to shift, multiplying by 8 // get Masks by shifting 0xff and shift amount // shift bits to required position // combine results int nShift = n<< 3; int mShift = m<< 3; int nMask = x & (255 << nShift); int mMask = x & (255 << mShift); nMask = 255 & (nMask >> nShift); mMask = 255 & (mMask >> mShift); nMask = nMask << mShift; mMask = mMask << nShift; int xSwapped = ((255 << nShift) | (255 << mShift)); return (~xSwapped & x) | nMask | mMask;}不确定我缺少什么,谢谢。 (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 看起来您正在使用设置为旧C标准的C编译器。在C99之前,您不能将可执行语句放在声明之前。您可以通过将xSwapped的声明移到顶部来解决此问题:int nShift = n<< 3;int mShift = m<< 3;int nMask = x & (255 << nShift);int mMask = x & (255 << mShift);int xSwapped; // DeclarationnMask = 255 & (nMask >> nShift);mMask = 255 & (mMask >> mShift);nMask = nMask << mShift;mMask = mMask << nShift;xSwapped = ((255 << nShift) | (255 << mShift)); // Assignmentreturn (~xSwapped & x) | nMask | mMask;关于c - 测试功能时未知的解析错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39091028/ (adsbygoogle = window.adsbygoogle || []).push({});
10-09 19:31