写C / C ++的#include宏 [英] Write a macro for C/C++ #include

查看:165
本文介绍了写C / C ++的#include宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在AS / 400这有时非POSIX工作。我们还需要编译我们在UNIX上code。我们有一个问题用简单的东西为的#include

I work on AS/400 which is sometimes non-POSIX. We also need to compile our code on UNIX. We have an issue with something as simple as #include.

在AS / 400,我们需要写:

On AS/400, we need to write:

#include "*LIBL/H/MYLIB"

在UNIX上,我们需要写

On UNIX, we need to write

#include "MYLIB.H"

目前,我们在每一个C / C ++文件的顶部,这(丑陋的)块:

At the moment we have this (ugly) block at the top of each C/C++ file:


#ifndef IS_AS400
    #include "*LIBL/H/MYLIB"
    /* others here */
#else
    #include "MYLIB.H"
    /* others here */
#endif

我们希望一个统一的宏。这可能吗?我不知道该怎么写了。

We would like a unified macro. Is this possible? I don't know how to write it.

在理想情况下,所产生的语法是:

Ideally, the resulting syntax would be:

SAFE_INCLUDE("MYLIB")

这将扩大正确每个平台上

that would expand correctly on each platform.

请指教。

推荐答案

您可以简单地的#include 在每一个包含源文件的一些单独的头说难听的#ifndef 只有一次。这是一个常见的​​做法呢。

You can simply #include some separate header in every of your source files containing that ugly #ifndef just once. It's a common practice anyway.

这篇关于写C / C ++的#include宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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