在C语言preprocessor例子 [英] Preprocessor examples in C language

查看:142
本文介绍了在C语言preprocessor例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

欲Çpreprocessor指令的一些实例中,如:

I want some examples of C preprocessor directives, such as:

#define pi 3.14
#define MAX 100

我只知道这个。
我想知道的比这更多,更多关于preprocessor指令。

I know only this. I want to know more than this, more about preprocessor directives.

推荐答案

最大的例子是

 #include<stdio.h>

但也有相当数量。您还可以定义宏:

But there are a fair amount. You can also define macros:

 #define MAX(X,Y) (((X) > (Y)) ? (X) : (Y))

和使用头警卫

#ifndef A_H
#define A_H

// code

#endif

有专有的扩展,编译器定义,让你给处理指令:

There are proprietary extensions that compilers define to let you give processing directives:

#ifdef WIN32 // WIN32 is defined by all Windows 32 compilers, but not by others.
#include <windows.h>
#else
#include <unistd.h>
#endif

和if语句原因也可用于注释

And the if statement cause also be used for commenting:

#if 0

int notrealcode = 0;

#endif

我经常使用的preprocessor进行调试版本:

I often use the preprocessor to make debug builds:

#ifdef EBUG
printf("Debug Info");
#endif

$ gcc -DEBUG file.c //debug build
$ gcc file.c //normal build

和其他人一样指出有很多地方可以得到更多的信息:

And as everyone else has pointed out there are a lot of places to get more information:

  • http://predef.sourceforge.net/
  • http://en.wikipedia.org/wiki/C%5Fpreprocessor
  • http://gcc.gnu.org/onlinedocs/cpp/

这篇关于在C语言preprocessor例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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