开发者

"error: expected identifier or ‘(’ before numeric constant" –?

开发者 https://www.devze.com 2023-01-24 11:20 出处:网络
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?

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-----*/
#defi开发者_JAVA百科ne   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


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:

//                  v Make this the last character on the line
#define NOT()       \
  ( NOT_OP << 28 ) 


Macro's should be written on 1 line, not 2.

This is wrong:

#define NOT()
  ( NOT_OP << 28 )

This is right:

#define NOT() ( NOT_OP << 28 )

If you really want to write it on multiple lines, use a backslash to 'escape' the new line. like this:

#define NOT() \
  ( NOT_OP << 28 )


Hmmm... I guess you're not putting the subsitution for the #define in a different line, right?

#define JMP(address)
( (JMP_OP << 28) | (address) )

should be

#define JMP(address) ( (JMP_OP << 28) | (address) )

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消