AlphaGoku
AlphaGoku

Reputation: 1020

Why does my code give `Structure-return value does not match function type` compile error?

I have code as:

typedef struct t
{
    uint8 a[100];

}t;

t tt; //object of the struct
f(&tt); //some file calling the func

//function body in some file
uint8 *f(const struct t *ptr)
{
    return ptr->a;
}

When I try to build I get the error:

Return value type does not match the function type.

Am I missing something?

Upvotes: 1

Views: 168

Answers (1)

Iharob Al Asimi
Iharob Al Asimi

Reputation: 53006

You need to use the name of the type, there is no struct t type defined anywhere in your code, so

uint8 *f(t *const tt);

should be the function signature, of course I suppose you are using meaninful names in your real code.

Also, note that I didn't make the pointee const because if you return a non-const pointer to a const pointer to the structure then undefined behavior might happen, the alternative being of course

const uint8 *f(const t *const tt);

The second const, just prevents accidentaly reassigning tt.

Upvotes: 1

Related Questions