#define B 100+B
main()
{
int i= B;
}
我知道这是错误的,但出于好奇,当我编译它时,我得到了一个奇怪的错误:
"B未在这一范围内宣布“。
为什么会这样呢?如果此错误是因为编译器在宏替换后删除了它,那么下面的代码如何正常工作,当B在提供给A之前必须已经删除了?
#define B 100
#define A 100+B
main()
{
int i= B;
int j =A;
}
我正在尝试建立一个程序,解析和列出了头文件的内容。到目前为止,一切顺利,我发现解析和列出我编写的头文件很容易,但是当我开始解析跨平台API头文件时,事情就变得混乱了。
我目前的方法相当简单,下面是一个解析以下函数的伪代码示例:
void foo(int a);
void is a type, so we are dealing with instancing a type
foo is the name of that type
foo is followed by brackets, meaning it is a function of type void named foo
in
所以我在尝试将一堆重复的代码行压缩成一个makefile格式时遇到了麻烦:
dir := XXX
include dir/Makefile
VAR_1 += $(VAR2) # where VAR2 and VAR4 are defined in the included makefile
VAR_3 += $(VAR4)
转换为类似如下的形式:
dir:= XXX1 XXX2 XXX3 ...
$(foreach elements,$(dir),$(eval $(call function,$(elements))))
define function
$(
假设我有两个宏注释类,在展开期间定义了它们的字段之后,一个依赖于另一个:
@Annotation case class A(i: Int) @Annotation case class B(a: A)
我需要在A之前扩展B,但是定义的顺序并不能保证这一点。
例如,将B作为类型参数引用到不相关的编译单元中的对象,例如:
class X{val b = B(A(1))}在一个文件中,class Y{Z[B]}在另一个文件中,
导致B首先展开,因此我的编译失败。
在这种情况下,是什么决定了宏观扩张的顺序?有什么办法强制执行所需的命令吗?
谢谢你的意见,
朱利安
我希望有人能对如何控制/指定宏扩展的顺序有一个想法。下面是上下文:
// 32 bit increments, processor has registers for set, clear and invert
#define CLR_OFF 1
#define SET_OFF 2
#define INV_OFF 3
#define SET(reg,bits) *((volatile unsigned long*)(& reg+SET_OFF)) = bits
//Now if I use this I can do it quite nicely with
#define STA
我有一些宏可以很容易地在寄存器中定义位字段(我使用这些宏来读取、修改、写入操作、设置、获取等等)。我得到了一个我不明白的编译器错误。
// used just for named arguments -- to make the values more clear when defined
#define FLDARGS(dwOffset, bitStart, bitLen) dwOffset, bitStart, bitLen
// extract just the dwOffset part
#define FLD_DWOFFSET(dwOffset, bitStart, bitLen)