#define SOUND_SPEED 0.034;
int rtt; //round trip time in microsecond
double distance;
distance = (double)(rtt*SOUND_SPEED)/2;
它报错了:在“/”标记之前期望表达式。是因为我不能使用宏定义小数或其他原因吗?
#define SOUND_SPEED 0.034;
int rtt; //round trip time in microsecond
double distance;
distance = (double)(rtt*SOUND_SPEED)/2;
去掉分号:
#define SOUND_SPEED 0.034;
^
distance = (double)(rtt*SOUND_SPEED;)/2;
^
gcc -E foo.c
。 - Arun#define SOUND_SPEED 0.034;
^
;
实际上,你永远不应该以;
结束宏:
PRE11-C. 不要以分号结尾宏定义https://www.securecoding.cert.org/confluence/display/seccode/PRE11-C.+Do+not+conclude+macro+definitions+with+a+semicolon
//
注释。根据你的编译器,可能不被允许。//
注释会给出精确的错误消息,而对于定义中多余的;
则会给出完全不同的错误消息。//
被默认接受。 - ouah