Macro definition error in C?

╄→гoц情女王★ 提交于 2019-12-02 00:01:18

Drop the semicolon:

#define SOUND_SPEED 0.034; 
                         ^

If you keep it the generated code will look like this:

distance = (double)(rtt*SOUND_SPEED;)/2;
                                   ^
#define SOUND_SPEED 0.034;
                         ^

Do not use the trailing ;

Actually you should never terminate a macro with a ;:

PRE11-C. Do not conclude macro definitions with a semicolon https://www.securecoding.cert.org/confluence/display/seccode/PRE11-C.+Do+not+conclude+macro+definitions+with+a+semicolon

You're using C, but you're trying to use a C++ style // comment. Depending on your compiler, that may not be allowed.

Edit: In fact, gcc -c89 -ansi gives that exact error message for a // comment and a totally different one for the extraneous ; in the define.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!