我的程序如下
unsigned long Ms[256]={0xa5c66363, 0x84f87c7c, 0x99ee7777,...};
#define sub(x){\
  x[0] = Ms[x[0]]^Ms[x[1]]^\
      Ms[x[2]]^Ms[x[3]];\
  x[1] = Ms[x[3]]^Ms[x[0]]^\
      Ms[x[1]]^ Ms[x[2]];\
  x[2] = Ms[x[2]]^Ms[x[3]]^\
      Ms[x[0]]^ Ms[x[1]];\
  x[3] = Ms[x[1]]^Ms[x[2]]^\
      Ms[x[3]]^ Ms[x[0]];\
};
编译时出现error C2143: syntax error : missing ';' before '}',而且还出现了三次同样的时间。
哪位高手知道这是为什么?

解决方案 »

  1.   

    我这里编译成功.rebuild all一下
      

  2.   

    #define sub(x){\
                  ^ 这儿有空格没有?
      

  3.   

    没有问题啊,
    你怎么用的?我用以下方法,编译连接通过.#include <stdio.h>
    unsigned long Ms[256]={0xa5c66363, 0x84f87c7c, 0x99ee7777};
    #define sub(x){\
      x[0] = Ms[x[0]]^Ms[x[1]]^\
          Ms[x[2]]^Ms[x[3]];\
      x[1] = Ms[x[3]]^Ms[x[0]]^\
          Ms[x[1]]^ Ms[x[2]];\
      x[2] = Ms[x[2]]^Ms[x[3]]^\
          Ms[x[0]]^ Ms[x[1]];\
      x[3] = Ms[x[1]]^Ms[x[2]]^\
          Ms[x[3]]^ Ms[x[0]];\
    };
    main()
    {
    char k[4]={1,2,3,4};
    sub(k);
    printf("K[0]=%d\nK[1]=%d\nK[2]=%d\nK[3]=%d\n",k[0],k[1],k[2],k[3]);
    }  结果:
    K[0]=11
    K[1]=119
    K[2]=0
    K[3]=99
      

  4.   

    我的程序是这样的,宏替换放在tbl.h文件中,a.cpp文件调用tbl.h中定义的一系列宏。//tbl.h
    long e1[256]={12,232,...,222};
    long e2[256]={22,48,...,99};
    long e3[256]={5,56,...,45};
    long e4[256]={65,2,...,324};
    long d1[256]={43,23,...,67};
    long d2[256]={67,56,...,65};
    long d3[256]={80,35,...,7};
    long d4[256]={2,98,...,02};#define GetByte1(x) ( (x & 0xFF) )
    #define GetByte2(x) ( (x >> 8) & 0xFF )
    #define GetByte3(x) ( (x >> 16) & 0xFF )
    #define GetByte4(x) ( (x >> 24) & 0xFF ) #define sub(x) {\
    x[0] = e1[GetByte4(x[0])] ^ e2[GetByte3(x[1])] ^ \
           e3[GetByte2(x[2])] ^ e4[GetByte1(x[3])]; \
    x[1] = e1[GetByte4(x[1])] ^ e2[GetByte3(x[2])] ^ \
           e3[GetByte2(x[3])] ^ e4[GetByte1(x[0])]; \
    x[2] = e1[GetByte4(x[2])] ^ e2[GetByte3(x[3])] ^ \
           e3[GetByte2(x[0])] ^ e4[GetByte1(x[1])]; \
    x[3] = e1[GetByte4(x[3])] ^ e2[GetByte3(x[0])] ^ \
           e3[GetByte2(x[1])] ^ e4[GetByte1(x[2])]; \
    }   //此行出错#define isub(x) {\
    x[0] = d1[GetByte4(x[0])] ^ d2[GetByte3(x[1])] ^ \
           d3[GetByte2(x[2])] ^ d4[GetByte1(x[3])]; \
    x[1] = d1[GetByte4(x[1])] ^ d2[GetByte3(x[2])] ^ \
           d3[GetByte2(x[3])] ^ d4[GetByte1(x[0])]; \
    x[2] = d1[GetByte4(x[2])] ^ d2[GetByte3(x[3])] ^ \
           d3[GetByte2(x[0])] ^ d4[GetByte1(x[1])]; \
    x[3] = d1[GetByte4(x[3])] ^ d2[GetByte3(x[0])] ^ \
           d3[GetByte2(x[1])] ^ d4[GetByte1(x[2])]; \
    }       //此行出错#define a(x) ((x<<24)|(x<<16)|(x<<8)|x)//a.cpp
    #include "tbl.h"
    void a1(long x,long y,int z)
    {                                //此行错误
    ...
    sub(x);
    ...
    }编译时出现
    f:\tbl.h(25) : error C2143: syntax error : missing ';' before '}'
    f:\tbl.h(25) : error C2143: syntax error : missing ';' before '}'
    f:\tbl.h(25) : error C2143: syntax error : missing ';' before '}'
    f:\tbl.h(36) : error C2143: syntax error : missing ';' before '}'
    f:\tbl.h(36) : error C2143: syntax error : missing ';' before '}'
    f:\a.cpp(39) : error C2143: syntax error : missing ';' before '{'
    f:\a.cpp(39) : error C2447: missing function header (old-style formal list?)
    f:\a.cpp(754) : error C2017: illegal escape sequence
    f:\a.cpp(763) : error C2601: 'a1' : local function definitions are illegal
    f:\a.cpp(779) : fatal error C1075: end of file found before the left brace '{' at 'f:\a.cpp(763)' was matched
    test5.cpp
    Error executing cl.exe.rijn.exe - 10 error(s), 0 warning(s)