3
我有下面的函數,它似乎應該是這樣,但是當通過測試程序運行程序時,我給出了錯誤:解析錯誤:[int xSwapped =((255 < < nShift)|(255 < < mShift));]和 未聲明的變量`xSwapped':[return(〜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;
}
不確定我在想什麼,謝謝。
你使用MSVC(或C89編譯器)? – BLUEPIXY
@BLUEPIXY否,不在窗口上測試儀使用MIT CILK組的ANSI C編譯器如果使用GCC,使用'-std = c99'選項 – Silverfin
。或者該行移動到'int mShift = m << 3;' – BLUEPIXY