Ada有预处理器吗? [英] Does Ada have a preprocessor?

查看:87
本文介绍了Ada有预处理器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要在C / C ++中支持多个平台,可以使用预处理器来启用条件编译。例如,

To support multiple platforms in C/C++, one would use the preprocessor to enable conditional compiles. E.g.,

#ifdef _WIN32
  #include <windows.h>
#endif

您如何在Ada中做到这一点? Ada有预处理器吗?

How can you do this in Ada? Does Ada have a preprocessor?

推荐答案

您的问题的答案是否定的,Ada没有构建的预处理器语言。这意味着每个编译器可能有也可能没有,并且没有用于预处理和条件编译之类的统一语法。

The answer to your question is no, Ada does not have a pre-processor that is built into the language. That means each compiler may or may not have one and there is not "uniform" syntax for pre-processing and things like conditional compilation. This was intentional: it's considered "harmful" to the Ada ethos.

几乎总是有办法避免缺少预处理器,但通常解决方案可能有点麻烦。例如,您可以将特定于平台的功能声明为 separate,然后使用构建工具来编译正确的功能(或者是项目系统,使用编译指示主体替换,或者是非常简单的目录系统...放置所有Windows文件在/ windows /和/ linux /中的所有linux文件中,并包括适用于该平台的目录。)

There are almost always ways around a lack of a preprocessor but often times the solution can be a little cumbersome. For example, you can declare the platform specific functions as 'separate' and then use build-tools to compile the correct one (either a project system, using pragma body replacement, or a very simple directory system... put all the windows files in /windows/ and all the linux files in /linux/ and include the appropriate directory for the platform).

GNAT意识到,有时您需要一个预处理程序并创建了gnatprep。无论编译器如何,它都可以工作(但是您需要将其插入到构建过程中)。同样,对于简单的事情(例如条件编译),您可以只使用c预处理器,甚至可以滚动自己的非常简单的预处理器。

All that being said, GNAT realized that sometimes you need a preprocessor and has created gnatprep. It should work regardless of the compiler (but you will need to insert it into your build process). Similarly, for simple things (like conditional compilation) you can probably just use the c pre-processor or even roll your own very simple one.

这篇关于Ada有预处理器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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