parameter has incomplete type in C

10,528

Solution 1

It needs to be like this:

enum mips_opcode { add = 0, addu, sub, subu }; // type name is "enum mips_opcode"
typedef enum mips_opcode mips_opcode_t;        // type alias

Or even:

typedef enum { add = 0, addu, sub, subu } mips_opcode_t; // alias of anon. type

Don't confuse type names and variables!

(By the way, Posix reserves _t suffixes for types, I believe...)

Solution 2

This line is the culprit:

enum { add = 0, addu, sub, subu } mips_opcode;

You're declaring a variable called mips_opcode, of an anonymous enum type.

It should read:

enum mips_opcode { add = 0, addu, sub, subu };

The name of the enum list goes right after the word enum.

Share:
10,528
hakuna matata
Author by

hakuna matata

Updated on June 04, 2022

Comments

  • hakuna matata
    hakuna matata almost 2 years

    I'm writing some code, when I'm trying to test my code till now, I get an error.

    Here is my code:

    #include <stdio.h>
    
    enum { add = 0, addu, sub, subu } mips_opcode;
    typedef enum mips_opcode mips_opcode_t;
    
    typedef unsigned char byte; // 8-bit int
    
    struct mips {
        char *name;
        byte opcode;
    };
    typedef struct mips mips_t;
    
    void init (mips_t *out, char *name_tmp, mips_opcode_t opcode_tmp) {
        out->name = name_tmp;
        out->opcode = (byte)opcode_tmp;
    }
    
    int main (void) {
        pritnf("no error i assume\n");
    
        return 0;
    }
    

    and the error in the commmand-line is:

    main.c:14:55: error: parameter 3 ('opcode_tmp') has incomplete type
    

    Can't I use enums as parameter or what am I doing wrong here?