vala程序预处理指令
百度了很久都找不到关于vala程序预处理指令的中文资料,于是我到官网找了英文资料,现在作一下简单介绍。本身就很简单!
预处理指令的作用
当我们需要选择性的编译某一部分代码时,例如某个函数在windows上和linux上需要不同的代码来实现,就需要在程序中加入预处理指令,编译时使用宏来指定跳过哪些代码、编译哪些代码。
逻辑选择指令
一共有4个:
-
#if
– 如果,后面跟一个宏或宏表达式 -
#elif
– 否则如果,后面跟一个宏或宏表达式 -
#else
– 否则 -
#endif
– 结尾
上面4个指令的意思一目了然,#if
和#elif
后面跟上宏作为条件。程序中是这样的:
#if COND1 [ vala code 1 ] #elif COND2 [ vala code 2 ] #else [ vala code 3 ] #endif
定义宏
vala
程序内部是不能定义宏的,只能使用valac
的参数-D
定义,用法如下:
valac -D CONDX program.vala
宏表达式
#if
和#elif
后面的条件表达式不但可以是单独的宏,还可以是几个宏的逻辑表达式,格式如下:
- “或”表达式:
COND1 [ || COND2 ]
- “与”表达式:
COND1 [ && COND2 ]
- “非”表达式:
! COND1
(英文资料里!
后面有空格,经本人验证,有无空格都可以) - “等于”表达式:
COND1 == COND2
(一个存在,一个不存在) - “不等于”表达式:
COND1 != COND2
(两个都存在)
一个宏的名字如果定义了,它的值就是true
,否则就是false
。利用括号可以组合多个表达式。
下面是英文资料:\
vala-code: [ any vala code ] [ pp-condition ] [ any vala code ] pp-condition: #if pp-expression vala-code [ pp-elif ] [ pp-else ] #endif pp-elif: #elif pp-expression vala-code [ pp-elif ] pp-else: #else vala-code pp-expression: pp-or-expression pp-or-expression: pp-and-expression [ || pp-and-expression ] pp-and-expression: pp-binary-expression [ && pp-binary-expression ] pp-binary-expression: pp-equality-expression pp-inequality-expression pp-equality-expression: pp-unary-expression [ ==pp-unary-expression ] pp-inequality-expression: pp-unary-expression [ !=pp-unary-expression ] pp-unary-expression: pp-negation-expression pp-primary-expression pp-negation-expression: ! pp-unary-expression pp-primary-expression: pp-symbol ( pp-expression ) true false pp-symbol: identifier The semantics of the preprocessor are very simple: if the condition is true then the Vala code surrounded by the preprocessor will be parsed, otherwise it will be ignored. A symbol evaluates to true if it is defined at compile-time. If a symbol in a preprocessor directive is not defined, it evaluates to false.
原文地址:https://www.jianshu.com/p/d737d0aad8a4
相关推荐
-
Nginx编译安装lua-nginx-module 服务器
2019-9-15
-
Kylin集群部署和cube使用 服务器
2020-6-13
-
docker-compose使用备忘(转) 服务器
2019-9-6
-
Linux 下的 Docker 安装与使用 服务器
2019-5-23
-
MySQL安装及基础命令 服务器
2019-8-15
-
Kubernetes 时代的安全软件供应链 服务器
2020-6-24
-
Kafka基于topic的分区设计 服务器
2020-6-8
-
如何使用 Weave 以及 Docker 搭建 Nginx 反向代理/负载均衡服务器 服务器
2019-3-11
-
eclipse如何将项目上传到码云 服务器
2019-7-26
-
在Linux上使用Python和Flask创建你的第一个应用 服务器
2019-3-14