#define causes an “expected primary-expression” error

可紊 提交于 2019-12-05 09:48:05

Remove the semicolon - you will be good - the semicolon is included in the substitution

Sometimes it is useful to get the compiler to run the preprocessor only. With gcc/g++ you can do something like

gcc -E file.c > result.txt

This will show you how the macro expanded (hint start at the end of the file and work up)

I recommend replacing the macro with a constant:

const int N = 10;

It's best to avoid macros when you can. Macros don't have any scope. They are a global text substitution. The compiler never sees them, so if you use a debugger it won't know about them. There are probably other reasons not to use them that I'm forgetting.

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