关于C语言的问题:什么是宏? [英] Question about the C language: what is a macro?

查看:102
本文介绍了关于C语言的问题:什么是宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是宏?为什么在C语言中使用它?

删除了喊叫

What is a macro? Why it is used in C?

removed shouting

推荐答案

不要喊叫(不要只使用大写字母)!太粗鲁了!
阅读此内容: 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://stackoverflow.com/questions/1358232/why-use-macros-in-c [ ^ ]
http://gcc.gnu.org/onlinedocs/cpp/Macros.html[^]
http://stackoverflow.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)
      {
        //...
      }


      这篇关于关于C语言的问题:什么是宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆