有没有办法连接2个字符串文字以形成包含路径?
代码存根:
#define INCLUDE_DIR "/include"
#include INCLUDE_DIR "/dummy.h"
Run Code Online (Sandbox Code Playgroud)
看看这个问题,答案指向不同的方向(编译器命令行).它提到这里,这似乎是不可能的,但我不知道是否该主题已经挖够了.
(我确实有一个与此相关的用例,请仅关注此问题的答案/评论.)
这不能按预期工作:
#define stringify(x) #x
printf("Error at line " stringify(__LINE__));
Run Code Online (Sandbox Code Playgroud)
这有效:
#define stringify1(x) #x
#define stringify(x) stringify1(x)
printf("Error at line " stringify(__LINE__));
Run Code Online (Sandbox Code Playgroud)
预处理用于扩展此类宏的优先级是什么?
我对如何在#include指令中使用宏感到困惑.我这样做了:
#include "../../../../GlobalDefintions.h"
#include "../../../../lib/libc++/" ARCH_FAMILY_S "/" ARCH_S "/stkl/printkc/printkc.h"
Run Code Online (Sandbox Code Playgroud)
GlobalDefintions.h:
#ifndef _GlobalDefintions_
#define _GlobalDefintions_
/*Architecture Information Start*/
#define ARCH i386
#define ARCH_FAMILY x86
#define ARCH_S "i386"
#define ARCH_FAMILY_S "x86"
/*Architecture Information End*/
#endif /*_GlobalDefintions_*/
Run Code Online (Sandbox Code Playgroud)
但是这给了我的是:
kernel.c++:24:88: fatal error: ../../../../lib/libc++/: No such file or directory #include "../../../../lib/libc++/" ARCH_FAMILY_S "/" ARCH_S "/stkl/printkc/printkc.h"
有没有办法成功追加ARCH_FAMILY_S和ARCH_S我的#include指令字符串?
我有一组包含在很远的目录中,这意味着包含它们需要很长的包含,例如:
#include "../../Path/to/my/file.h"
Run Code Online (Sandbox Code Playgroud)
在我有多个这样的地方它变得有点不方便所以我想我可以对目录路径使用#define,然后连接我需要的文件名,即
#define DIR "../../Path/to/my/"
#define FILE1 "file.h"
#define FILE2 "anotherFile.h"
#include DIR FILE1 // should end up same as line in first example after pre-proc
Run Code Online (Sandbox Code Playgroud)
然而,这不起作用......无论如何在适合于此的C预处理器的工作中进行连接?