0

これまでコードをテストしようとしていましたが、テスト実行をコンパイルするとエラーが発生します。

これが私のコードです:

mips_op.hファイル

#ifndef MIPS_OP_H
#define MIPS_OP_H

typedef enum {
    R, I, J
} op_type;

typedef struct op_instr {
    op_type op_t; // instruction type {R, I, J}
    int opcode : 6; // instruction opcode - 6-bit integer

    // if the instruction type is J
    #if op_t == J

    int address : 26; // address to jump to - 26-bit integer

    #else // if the instruction type is R or I

    int rs : 5; // the output - 5-bit integer
    int rt : 5; // the first operand - 5-bit integer

        #if op_t == R // if instruction type is R

        int rd : 5; // the second operand - 5-bit integer
        int shamt : 5; // the shift amount field - 5-bit integer
        int funct : 6; // the function field

        #endif

        #if op_t == I // if instruction type is R

        int immediate : 16; // the immediate field - 16-bit integer

        #endif

    #endif
};

#endif

ここにmain.cファイルがあります

#include <stdio.h>
#include "mips_op.h"

int main (void) {
    printf("Before instr\n");

    op_instr add;

    printf("After instr\n");

    return 0;
}

これが私が得ているエラーです

In file included from main.c:2:0:
mips_op.h:9:10: error: expected ')' before 'op_t'
main.c: In function 'main':
main.c:7:2: error: unknown type name 'op_instr'

私のコードの何が問題になっていますか?なぜこのエラーが発生するのですか?

ありがとう

編集:角かっこを中かっこに修正しました

4

3 に答える 3

2

( の代わりに { 構造体の周りに使用していると思います。それとも間違っていますか?

于 2012-11-15T22:46:26.687 に答える
2

構造体定義の「(」を「{」に置き換えます

typedef struct op_instr
**{**
   ...
**}**

編集:この問題が発生している可能性があります

「基本的に、通常の C プリプロセッサ ディレクティブ、通常の C 言語要素、および Arduino IDE とコンパイラ チェーンの不可解な内部構造の間には複雑な相互作用があります。

私が知る限り、単純な宣言とほとんどの実行可能コードを #if で囲んで問題なくラップできますが、単純な typedef 構造体など、それより複雑なものを条件文内に配置すると、奇妙な問題が発生します。

実際、特に関数宣言で後続のタグを使用しようとすると、typedef だけで問題が発生する可能性があります。これらの線に沿って何も考えないでください:」

于 2012-11-15T22:46:38.200 に答える
0

あなたの差し迫った問題は、構造体スコープに {} の代わりに () を使用していることです。

Paul R が言うように、他にも問題があるようです。

于 2012-11-15T22:48:37.763 に答える