-1

現在、ポインターを持つ typedef の概念を理解するのに苦労しています。これがあるとしましょう:

struct command
{
    int type;
    int *input;
    int *output;
    union{
        struct command *command[2];
        char **word;
    }u;
};

typedef struct command *command_t;

command_t read_command(){
    command_t main1;
    command_t main2;
    //some code that set the instance of main1
    //some code that set the instance of main2
    if(main1->u->command[0] == main2->u->command[1])
    {
        main1 = *main2;
        main2 = NULL;
    }
    //some other code in here
}

私の質問は、 command_t がコマンドへのポインターとして定義されているためです。if ステートメントでは、main2 のインスタンスを main1 に配置する前に、最初に main2 を逆参照する必要がありますか? このようなことをすると、「main2 = NULL;」というステートメントを薄くします。オブジェクトmain1をNULLに設定しませんよね?ありがとうございました。

4

2 に答える 2