2007 11 11 20 02 在C語言中的指數表示式

話說今天,有新的程式碼要使用build machine去build official build,
所以需要先試build一下,結果在linux下發現奇怪的錯誤。

// ---- sample code -----
#include <stdio.h>
int main()
{
  int i=0x0E+3;
  printf("%d\n",i);
  return 0;
}

// ---- compiling error -----
test.c:4:9: error: invalid suffix "+3" on integer constant

看了一下,發覺gcc會把 0x0E+3這個當程式指數表示式,
可是在VC 6.0 則完全沒有這個問題,只是單純當作0x11來運算。
可是你只需要把0x0E + 3 多加個空白,gcc就不會誤解了。
後來又多試了幾個平臺,發現比較舊的C compiler都沒這個問題。
至於這個是不是gcc的特異功能,就不清楚了~~~