且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

关于C语言的问题:什么是宏?

更新时间:2023-02-18 16:07:30

不要喊叫(不要只使用大写字母)!太粗鲁了!
阅读此内容: http://en.wikipedia.org/wiki/C_preprocessor [
Don''t shout (don''t use only capital letters)! It is rude!
Read this: http://en.wikipedia.org/wiki/C_preprocessor[^]


http://gcc.gnu.org/onlinedocs/cpp/Macros.html [ http://***.com/questions/1358232/why-use-macros-in-c [ ^ ]
http://gcc.gnu.org/onlinedocs/cpp/Macros.html[^]
http://***.com/questions/1358232/why-use-macros-in-c[^]


宏是C 编译器甚至看不到的东西.

根据 quick-Google-search (宏-C预处理器 [ ^ ]):

A macro is something the C compiler not even sees.

According to the first entry in a quick-Google-search (Macros - The C Preprocessor[^]):

宏是已被赋予名称的代码片段.每当使用该名称时,它就会被宏的内容替换.
A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro.



也就是说:

  • C 预处理器的东西.
  • 使用Google,您可能会找到很多有关的文档.


  • That is:

    • macros are C preprocessor stuff.
    • Using Google you may find a lot of documentation about.
#define BUFSIZE  100
//...
int buf[BUFSIZE];
//...
if (k>BUFSIZE)
{
  //...
}



预处理器用数字100替换每次出现的宏BUFSIZE,因此 C编译器解析(类似)以下源:



the preprocessor replaces every occurrence of the macro BUFSIZE with the number 100, thus the C compiler parses (something like) the following source:

//...
int buf[100];
//...
if (k>100)
{
  //...
}