C Function Prototype With Struct Argument

后端 未结 2 1761
忘掉有多难
忘掉有多难 2021-01-13 06:46

I want to write a function prototype for a function, whose argument is a pointer to a struct.

int mult(struct Numbers *n)

However, the str

2条回答
  •  走了就别回头了
    2021-01-13 07:17

    You must forward the declaration of the structure to tell the compiler that a struct with that name will be defined:

    struct Numbers;
    
    int mult(struct Numbers *n) {
    
    }
    
    struct Numbers {
        int a;
        int b;
        int c;
    };
    

    Mind that the compiler is not able to determine the size in memory of the structure so you can't pass it by value.

提交回复
热议问题