“错误:预期的标识符或“(”在数字常量之前”“?
标题中的错误出现在该头文件中每个类似函数的宏的“#define
”行上(从第 45 行开始)。我做错了什么吗?
#ifndef ASSEMBLER_H
#define ASSEMBLER_H
/* Ports */
#define Input 0
#define Output 15
/* Registers */
#define Z 0
#define A 1
#define B 2
#define C 3
#define D 4
#define E 5
#define F 6
#define G 7
/* OP Codes */
/*-----Control--------*/
#define HLT_OP 0
#define JMP_OP 1
#define CJMP_OP 2
#define OJMP_OP 3
/*-----Load/Store-----*/
#define LOAD_OP 4
#define STORE_OP 5
#define LOADI_OP 6
#define NOP_OP 7
/*-----Math-----------*/
#define ADD_OP 8
#define SUB_OP 9
/*-----Device I/O-----*/
#define IN_OP 10
#define OUT_OP 11
/*-----Comparison-----*/
#define EQU_OP 12
#define LT_OP 13
#define LTE_OP 14
#define NOT_OP 15
/* Macros */
/*-----Control--------*/
#define HLT()
( HLT_OP << 28 )
#define JMP(address)
( (JMP_OP << 28) | (address) )
#define CJMP(address)
( (CJMP_OP << 28) | (address) )
#define OJMP(address)
( (OJMP_OP << 28) | (address) )
/*-----Load/Store-----*/
#define LOAD(dest, value)
( (LOAD_OP << 28) | ((dest) << 24) | (value) )
#define STORE(dest, value)
( (STORE_OP << 28) | ((dest) << 24) | (value) )
#define LOADI(dest, value)
( (LOADI_OP << 28) | ((dest) << 24) | (value) )
#define NOP()
( NOP_OP << 28 )
/*-----Math-----------*/
#define ADD(dest, op1, op2)
( (ADD_OP << 28) | ((dest) << 24) | ((op1) << 20) | ((op2) << 16) )
#define SUB(dest, op1, op2)
( (SUB_OP << 28) | ((dest) << 24) | ((op1) << 20) | ((op2) << 16) )
/*-----Device I/O-----*/
#define IN(reg)
( (IN_OP << 28) | ((reg) << 24) | (Input) )
#define OUT(reg)
( (OUT_OP << 28) | ((reg) << 24) | (Output) )
/*-----Comparison-----*/
#define EQU(reg1, reg2)
( (EQU_OP << 28) | ((reg1) << 24) | ((reg2) << 20) )
# define LT(reg1, reg2)
( (LT_OP << 28) | ((reg1) << 24) | ((reg2) << 20) )
#define LTE(reg1, reg2)
( (LTE_OP << 28) | ((reg1) << 24) | ((reg2) << 20) )
#define NOT()
( NOT_OP << 28 )
#endif
The error in the title occurs on the '#define
' line for every single function-like macro in this header file (starting at line 45). Am I doing something wrong?
#ifndef ASSEMBLER_H
#define ASSEMBLER_H
/* Ports */
#define Input 0
#define Output 15
/* Registers */
#define Z 0
#define A 1
#define B 2
#define C 3
#define D 4
#define E 5
#define F 6
#define G 7
/* OP Codes */
/*-----Control--------*/
#define HLT_OP 0
#define JMP_OP 1
#define CJMP_OP 2
#define OJMP_OP 3
/*-----Load/Store-----*/
#define LOAD_OP 4
#define STORE_OP 5
#define LOADI_OP 6
#define NOP_OP 7
/*-----Math-----------*/
#define ADD_OP 8
#define SUB_OP 9
/*-----Device I/O-----*/
#define IN_OP 10
#define OUT_OP 11
/*-----Comparison-----*/
#define EQU_OP 12
#define LT_OP 13
#define LTE_OP 14
#define NOT_OP 15
/* Macros */
/*-----Control--------*/
#define HLT()
( HLT_OP << 28 )
#define JMP(address)
( (JMP_OP << 28) | (address) )
#define CJMP(address)
( (CJMP_OP << 28) | (address) )
#define OJMP(address)
( (OJMP_OP << 28) | (address) )
/*-----Load/Store-----*/
#define LOAD(dest, value)
( (LOAD_OP << 28) | ((dest) << 24) | (value) )
#define STORE(dest, value)
( (STORE_OP << 28) | ((dest) << 24) | (value) )
#define LOADI(dest, value)
( (LOADI_OP << 28) | ((dest) << 24) | (value) )
#define NOP()
( NOP_OP << 28 )
/*-----Math-----------*/
#define ADD(dest, op1, op2)
( (ADD_OP << 28) | ((dest) << 24) | ((op1) << 20) | ((op2) << 16) )
#define SUB(dest, op1, op2)
( (SUB_OP << 28) | ((dest) << 24) | ((op1) << 20) | ((op2) << 16) )
/*-----Device I/O-----*/
#define IN(reg)
( (IN_OP << 28) | ((reg) << 24) | (Input) )
#define OUT(reg)
( (OUT_OP << 28) | ((reg) << 24) | (Output) )
/*-----Comparison-----*/
#define EQU(reg1, reg2)
( (EQU_OP << 28) | ((reg1) << 24) | ((reg2) << 20) )
# define LT(reg1, reg2)
( (LT_OP << 28) | ((reg1) << 24) | ((reg2) << 20) )
#define LTE(reg1, reg2)
( (LTE_OP << 28) | ((reg1) << 24) | ((reg2) << 20) )
#define NOT()
( NOT_OP << 28 )
#endif
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
预处理指令(如
#define
)以换行符终止,因此它只能是一行长。如果你想要多行宏定义,你需要转义换行符:A preprocessing directive (like
#define
) is terminated by a newline, so it can only be one line long. If you want a multi-line macro definition, you need to escape the newline:宏应该写在 1 行,而不是 2 行。
这是错误的:
这是正确的:
如果您确实想将其写在多行上,请使用反斜杠来“转义”新行。像这样:
Macro's should be written on 1 line, not 2.
This is wrong:
This is right:
If you really want to write it on multiple lines, use a backslash to 'escape' the new line. like this:
嗯...我想您没有将
#define
的替换放在不同的行中,对吗?应该
例如, 改为。
#define
声明必须仅在一行中,或者在一行末尾使用\
扩展至下一行。Hmmm... I guess you're not putting the subsitution for the
#define
in a different line, right?should be
instead, for example.
#define
declarations have to be in just one line, or use\
at the end of a line to expand to the next.