相关疑难解决方法(0)

包含#include指令的宏定义

有没有办法定义一个#include 在其体内包含指令的宏?

如果我只是把" #include",它给出了错误

C2162: "expected macro formal parameter"
Run Code Online (Sandbox Code Playgroud)

因为在这里我不是#用来连接字符串.
如果我使用" \# include",那么我收到以下两个错误:

error C2017: illegal escape sequence
error C2121: '#' : invalid character : possibly the result of a macro expansion
Run Code Online (Sandbox Code Playgroud)

有帮助吗?

c c++ macros c-preprocessor

34
推荐指数
5
解决办法
3万
查看次数

C#include filename中的连接字符串

当#including文件名(在C中)时,是否可以从另一个宏连接字符串.例如,

我有,

#define AA 10 
#define BB 20
Run Code Online (Sandbox Code Playgroud)

这些是随程序运行而变化的参数

该文件包括:

#include "file_10_20" // this changes correspondingly i.e. file_AA_BB
Run Code Online (Sandbox Code Playgroud)

是否有可能以#include "file_AA_BB"某种方式?我用谷歌搜索发现双磅操作符可以连接字符串,但找不到这样做的方法.

任何帮助,将不胜感激.

c macros concatenation include c-preprocessor

13
推荐指数
2
解决办法
4033
查看次数

包含路径的预处理器连接

我有一组包含在很远的目录中,这意味着包含它们需要很长的包含,例如:

#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预处理器的工作中进行连接?

c include c-preprocessor

2
推荐指数
1
解决办法
2043
查看次数

标签 统计

c ×3

c-preprocessor ×3

include ×2

macros ×2

c++ ×1

concatenation ×1