ca65:Include Guard生成“错误:预期标识符”

Que*_*ter 3 assembly c64 6502 ca65

为了学习如何使用ca65汇编程序,我一直在努力使include guards起作用。谷歌搜索和阅读《ca65用户指南》无济于事。这是产生错误的最小示例。

$ ls -l
total 16
-rw-r--r--  1 me  staff  60 Oct 22 19:40 65.inc
-rw-r--r--  1 me  staff  55 Oct 22 20:01 test.s
$
$ cat 65.inc
.ifndef _65_INC_
.define _65_INC_

.define NUMBER 1

.endif
$
$ cat test.s
.include "65.inc"
.include "65.inc"

    lda #NUMBER
    rts
$
$ ca65 test.s
65.inc(1): Error: Identifier expected
65.inc(2): Error: Identifier expected
65.inc(4): Error: Identifier expected
65.inc(4): Note: Macro was defined here
$
$ ls -l
total 16
-rw-r--r--  1 me  staff  60 Oct 22 19:40 65.inc
-rw-r--r--  1 me  staff  55 Oct 22 20:01 test.s
$
Run Code Online (Sandbox Code Playgroud)

如果我只包含65.inc 一次test.s它将毫无问题地组装,如下所示:

$ ls -l
total 16
-rw-r--r--  1 me  staff  60 Oct 22 19:40 65.inc
-rw-r--r--  1 me  staff  37 Oct 22 20:07 test.s
$
$ cat 65.inc
.ifndef _65_INC_
.define _65_INC_

.define NUMBER 1

.endif
$
$ cat test.s
.include "65.inc"

    lda #NUMBER
    rts
$
$ ca65 test.s
$
$ ls -l
total 24
-rw-r--r--  1 me  staff   60 Oct 22 19:40 65.inc
-rw-r--r--  1 me  staff  295 Oct 22 20:07 test.o
-rw-r--r--  1 me  staff   37 Oct 22 20:07 test.s
$
$ ca65 --version
ca65 V2.17 - Git 153bb29
Run Code Online (Sandbox Code Playgroud)

我想念什么?

Jes*_*ter 7

有点令人困惑的是.ifndef,朋友会把那些不是宏的符号应用于(.define定义宏)。因此,可能的解决方法是使用符号,例如

.ifndef _65_INC_
_65_INC_ = 1

.define NUMBER 1

.endif
Run Code Online (Sandbox Code Playgroud)

  • 它在那里也不起作用,只是因为实际上两次都没有包含文件,所以实际上从未使用过保护程序。与您的情况一样,如果只包含一次,则没有错误(但是,整个练习当然是不必要的)。 (4认同)
  • 谢谢杰斯特,这很有道理。我的代码的灵感来自第一个下载链接中的源代码:(https://csdb.dk/release/?id=32392)他确实使用.define,我想知道为什么它对他有用而不对我有用? (2认同)